Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
So, I'm trying to implement a program that calculates the degree of separation between 2 actors, for example if they both starred in the same movie then the degree of separation between them is 1. The problem is not how to calculate the degree of separation as I was able to demonstrate it, my problem is now I'm required to show all different shortest paths between these 2 actors, so if they starred in movie 0, movie 1, movie 7 together then the path should be movie 0 or movie 1 or movie 7. The problem is when I implemented my class I implemented it as an adjacency list (i.e ActorA : its neighbors ActorB, ActorC, ActorD) so when I implemented it I didn't include the movies. So, I did some research and I stumbled upon the concept of Bipartite Graphs but my question is how to represent it as an adjacency list? like from I gathered is that I'm supposed to make vertices for the actors and vertices for the movies so does that mean it's represented as this?

ActorA : Movie0, Movie1, Movie7
Movie0 : ActorA, ActorB , ActorC
ActorB : Movie0, Movie1, Movie2
.... etc
Posted
Comments
Sergey Alexandrovich Kryukov 20-Dec-15 21:35pm    
You should choose the representation of the graph, whatever it is, the way suitable for the set of operations of some calculations you need to do on the graph. As you did not explain your goals or the set of operations you need to implement, any particular advice on such presentation would not make too much sense. Adjacency list is just one of the ways to represent graphs. I don't understand what could be a problem. The definition of adjacency list clearly explain how a graph can be represented. Which part of it is unclear?

Yes, you mention that your goal is to point out some paths between actors, but you have to define it strictly. Do you mean that the path between actors should go through the movies where both have starred in? In all cases, it's not quite clear what would it mean, "all shortest"? I can guess, but you have to define it...

—SA
Member 12160712 20-Dec-15 22:03pm    
I'm sorry if I was a bit vague... No, what I meant is that I applied the Breadth first search algorithm to calculate the shortest path between each 2 actors, but now my problem is another 2 functions first a function called Relation Strength: If Actor A and actor B are directly linked with a degree of separation equal 1. The relation strength between them is three movies since they are directly appeared together in the three movies.
If Actor C and actor E are linked with a degree of separation equal 2 through either actor A, actor B or actor D. The relation strength should equal the max of the three options. The second function is to show this path, so in the situation for ActorA and Actor B, the path should be either movie0, movie1, movie7. So, now I would like to represent the graph while including the movies but I don't know how, so that's why I thought of the bipartite graph.
Sergey Alexandrovich Kryukov 20-Dec-15 22:29pm    
No problem, but I still did not get the rules for a valid link between two actors. From what you say, I can see this is not what I thought at first. If a such movie M exists that actor A and actor B are starring in it, it would be the degree of separation of 1, right? But how to define the situation of 2? Say, the only path from A to B lies through the actor D. What properties of D defines the arc between A and D and D and B? If you say it's the same (A and D were starring in movie1 and D and B starring in some movie2), that would be one of the possible definitions. Do I understand it right?

Now, it's not a big deal to find out the shortest path in a brute-force way, and it might be not the only path. You can find all paths and the degrees will be the lengths of them; and you would need to find the shortest ones; as soon as you find one way shorter than previous ones, you can forget all longer ways. So, I would apply "algorithm first" thinking: imagine how the algorithm works and design most suitable data structure for this algorithm.

But did I understand the problem correctly?

—SA
Member 12160712 20-Dec-15 22:37pm    
Yeah, you did understand it! I will try to think again of how to represent my graph, Thank you!
BillWoodruff 21-Dec-15 3:12am    
Is it really necessary to implement an object-graph database with nodes, vertices, etc., here ? I have implemented something similar to this, but I used standard .NET Generic data-structures. If you want to see an example of that code, just ask.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900