Animal behaviour

Started by
12 comments, last by CProgrammer 20 years, 2 months ago
I have a group of animals. Each has saved which of the other animals he likes to be in company with. Now I want to calculate a group in which all animals like eachother. I just cant seem to come up with a descent algorithm. Any ideas pointers? -CProgrammer
Advertisement
This isn''t exactly what you want, but look over this stuff for ideas

-~-The Cow of Darkness-~-
You''re searching for cycles in a directed graph.
Does somebody perhaps have a small code example in C/C++
for specifieing cycles in a directed graph?
-CProgrammer
Wait a sec. If I find out the cycle in a directed graph would that really be correct?
Lets say this example:
We have Animal A,B,C,D,E,F

A->B->C->D->A
is a cycle.
Then it isnt said that C likes A for instance.
-CProgrammer
To pick up your ABCDEF example...

Take animal A. Check which animals it likes to be with, animals B, D, E and F for instance. You can drop animal C already, as there will be at least one animal that doesn''t like C. So you''ll be left with animals A, B, D, E and F. Now go to the next animal (B) and check which animals in the group it doesn''t like. Eliminate those and go to the next one.

This method has its weaknesses, but it''s a very easy solution. The problem is, that if B doesn''t like E, but the other ones like E, if B gets thrown out by animal C, E isn''t in the list even though no animal is left in the group that doesn''t like E. You can probably work around this somehow by keeping another list of animals that have been thrown out and checking that list when you''ve assembled your basic group.

- Christoph

---
Teamwork Software - Stuff That Does Something
quote:Original post by Captain Nuss
To pick up your ABCDEF example...

Take animal A. Check which animals it likes to be with, animals B, D, E and F for instance. You can drop animal C already, as there will be at least one animal that doesn''t like C. So you''ll be left with animals A, B, D, E and F. Now go to the next animal (B) and check which animals in the group it doesn''t like. Eliminate those and go to the next one.

This method has its weaknesses, but it''s a very easy solution. The problem is, that if B doesn''t like E, but the other ones like E, if B gets thrown out by animal C, E isn''t in the list even though no animal is left in the group that doesn''t like E. You can probably work around this somehow by keeping another list of animals that have been thrown out and checking that list when you''ve assembled your basic group.

- Christoph

---
Teamwork Software - Stuff That Does Something



Thats a way to go yeah, although that problem may get tricky and CPU consuming, but i''ll think it through thanks.
-CProgrammer
one word:
boost::graph
Hey thanks guys. I think I found an answer now. Kinda a mix of everything.
-CProgrammer
If I understand your question correctly... google for "maximum clique".

This topic is closed to new replies.

Advertisement