matching two graphs with the lowest error - algorithm

I have two graphs that I would like to match (I am not sure this is the world I'm looking for).
In my first graph nodes represents teams (node value represents the number of people in the team) and links represent how close teams are on a scale of 1 to 5. Two teams working a lot together will have a stronger link than two teams that work sometimes together.
In my second graph nodes represent spaces (node value represents the available places in the space) and links represent how close the spaces are. If two spaces are on the same floor they will have a stronger link than two spaces that are not on the same floor.
I need to distribute the teams in the available spaces minimizing the distance between each linked team (two teams that have a strong link would be at the same floor for example).
My first question is : do you have a magic recipe that would solve this problem ?
My second question : If not, do you know in what direction I need to check (algorithm that could be reworked, lectures, articles ...).
Thank you very much.
Thoma

To answer the question in part, apparently there is no known polynomial-time algorithm to solve the problem, as the problem includes the graph isomorphism problem as a subproblem. This problem is neither known to be NP-complete nor has a polynomial algorithm been found.
More precisely, suppose that the room graph is exactly the team graph, where edges are not weighted. As an optimal solution would match each team to the corresponding room, an algorithm for the problem in the question would be able to identify the input graphs to be isomorphic.

After talking with some people, it seems that it might not be the best solution.
I will look in the direction of solvers to be abble to have define constraints.
Thank you.

Related

How to divide a connected weighted graph to N semi-equal subgraphs

I have a graph of many hundred nodes that are mainly connected with each other. I can do processing on entire graph but it really takes a lot of time, so I would like to divide it to smaller sub-graphs of approximately similar size.
With other words. I have a collection of aerial images and I do pairwise image matching on all of them. As a result I get a set of matches for each pair (pixel from first image matched with pixel on second image). Number of matches is considered as weight of this (undirected) edge. These edges then form a graph mentioned above.
I'm not so familiar with graph theory (as it is a very broad topic). What is the best algorithm for this job?
Thank you.
Edit:
This problem has a perfect analogy which I think is easier to understand. Imagine you have a set of people and their connections/friendships, like I social network. Each friendship has a numeric value/weight representing how good friends they are. So in a large group of people I want to get k most interconnected sub-groups .
Unfortunately, the problem you're describing is almost certainly NP-hard. From a graph perspective, you have a graph where each edge has a weight on it. You're trying to split the graph into relatively equal pieces while cutting the lowest total cost of edges cut. This problem is called the maximum k-cut problem and is NP-hard. If you introduce the constraint that you also want to try to make the pieces roughly even in size, you have the balanced k-cut problem, which is also NP-hard.
The good news is that there are nice approximation algorithms for these problems, so if you're looking for solutions that are just "good enough," then you can probably find a library somewhere that implements them. There are also other techniques like spectral clustering which work well in practice and are really fast, but which don't have any guarantees on how well they'll do.

Greedy algorithm for the following

I am trying to solve the following problem using Greedy Algorithm,
We have n friends and we want to give a present to each one of them. But we don't want to give the same present to two person who know each other. (if x knows y, then y knows x). People who do not know each other may take the same gift, it is okay. We want to minimize the number of distinct gifts given.
Here is what I thought, We try to make pairs of people who do not know each other, and give them all the same gift. But I am not sure whether this is a greedy algorithm. Also, we may want to find maximum group of people in which no one knows any other, so we can give hem the same gift. But can we do this? Can we find the maximum group of people who do not know each other?
Can anyone propose a greedy algorithm for the problem?
The problem you have mentioned is a restatement of Graph Coloring problem. You have to label the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. The link given below is to the Greedy Coloring Algorithm.
http://en.wikipedia.org/wiki/Greedy_coloring
This is graph coloring problem, and greedy algorithm for it is straightforward:
a greedy coloring is a coloring of the vertices of a graph formed by
a greedy algorithm that considers the vertices of the graph in sequence
and assigns each vertex its first available color

Finding a minimum/maximum weight Steiner tree

I asked this question on reddit, but haven't converged on a solution yet. Since many of my searches bring me to Stack Overflow, I decided I would give this a try. Here is a simple formulation of my problem:
Given a weighted undirected graph G(V,E,w) and a subset of vertices S in G, find the min/max weight tree that spans S. Adding vertices is not allowed. An extension of the basic model is adding edges with 0 weight, and vertices that must be excluded. This seems similar to the question asked here:
Algorithm to find minimum spanning tree of chosen vertices
There is also more insight into what values the edges can take. Each edge is actually a correlation probability, which I can encode in several ways, so the main questions I want to ask the graph are:
Given k vertices that must be connected, what are the top X min/max spanning trees that connect them, and what vertices do they pass through? As I understand it, this is the same question as asking the graph what is the highest probability of connecting all of the k vertices.
Getting more vague, is there a logical way to cluster the nodes?
As for implementation, I have the boost libraries installed, and once I get the framework rolling on this problem, I can deal with how to multi-thread it (if appropriate), what kind of graph to use, and how to store/cache the data, since the number of vertices and edges is going to be quite large.
Update
Looking at the problem I am trying to solve, it makes sense that it would be NP-complete. The real world problem that I am trying to solve involves medical diagnoses; specifically when the medical community is working on a problem with a specific idea in mind, and they need to take a step back and reconsider how they got there. What I want from the program I am trying to design is:
Given several conditions, tests, symptoms, age, gender, season, confirmed diagnosis, timeline, how can you relate them? What cells/tissues/organs/systems are touched? Are they even related?
Along with the defined groups that conditions/symptoms can belong to, is there a way to logically group the conditions/symptoms?
Example
Flu-like symptoms, red eyes, early pneumonia, and some of the signs of diabetes. Is there a way to relate all of the symptoms? Are there some tests that could be done to make it easier to determine? What systems are involved?
It just seemed natural to try and map this to a graph, or several graphs, and use probabilities as the correlation between different symptoms/conditions.
I have seen models for your problem that were mostly based on Bayesian inference and fuzzy logic. Bayesian inference networks express the relation between causes and effects e.g. smoking and lung cancer. Look here for a quick tutorial. You can apply fuzzy logic to that modelling to try to take into account the variablility in real life (as not everyone gets lung cancer).

How to find the quickest path between many locations which have time restrictions

I am trying to start on a personal research project that I have been brainstorming for a couple of years now. I am aware of graphs and algorithms for finding the best order in which to visit locations for the quickest time. However I am stuck on the next step of my research, are there research papers / algorithms that can solve this problem? Given a starting point and an end point with a number of "waypoints" that have to be visited. And some waypoints have time restrictions such as waypoint three has to be reached by 4:00 pm. So the algorithm will have to first sort the locations based on the time restrictions of them (if there are any) and then find the best order to visit each of the waypoints.
I have looked into many different algorithms/heuristics and I have searched for research papers on this topic but I cannot find anything definitive.
Thank you for the help in advance.
Never done anything like that but... elaborating on what has already told you BlueRaja, I have to say that most likely you already found your Grail (and, maybe, you are just not realizing it).
The time-related problem you are trying to solve looks like just another way to re-state the same space-related path-finding problem you already had to solve for travelling across your graph.
In other words, it looks like you have two graphs to traverse. The first one is the spatial one, represented by the net of waypoints you have to visit. The second one is the temporal (aka "time-related") graph of "time windows" you have to meet in order to not miss any bus/train/ship/airplane/whatever.
As long as I can see, you could use a regular path-finding/graph-crossing algorithm (Dijkstra, A*, contraction hierarchies, etc.) to traverse the spatial graph and re-use the same algorithm (or a very similar one) to traverse the time-related graph as well.
After all, both graphs are just a mathematical representation of a net of "constrains" (the points to be traversed, being them in space or in time) and can traversed using the same algorithm. Most likely, if you look at the code you are using to sort out your "time windows", you will see that it is already quite similar to a very simple space-related graph-traversing algorithm.
The main problem seems to be finding a good representation of the temporal graph (the net of "time windows" you have to respect). Most likely, it will have to be a graph of time-constrained spatial waypoints (spatial points, or "doors", with a "time window" attached to each of them).
In any case, there is no way to solve two problems with one single operation. First, you will have to find the "shortest path" that connects all of your time windows (in the required order) in the temporal graph (that is: you have to sort them out, as you are already doing). Second, you will have to find the shortest paths between any pair of time windows in the spatial graph (and check if the shortest/fastest path is fast enough to meet the next time window).

Algorithm Optimization - Shortest Route Between Multiple Points

Problem: I have a large collection of points. Each of these points has a list with references to other points with the distance between them already calculated and stored. I need to determine the shortest route that begins from an origin and passes through a specific number of points to any destination.
Ex: I'm on vacation and I'm staying in a specific city. I'm making a ONE WAY trip to see ANY four cities and I want to travel the least distance possible. I cannot visit the same city more than once.
Current solution: Right now I'm just iterating through every possibility manually and storing the shortest path. This works but feels inefficient. Also, this problem will eventually be expanded to include searching from multiple origin points to multiple destination points, so I think that might explode the search space.
What is the better way to search for the shortest route?
Answering to the updated post, your solution of checking every possibility is optimal (at least, noone has discovered better algorithms so far). Yes, that's a travelling salesman, whose essense is not touching every city, but touching every city once. If you don't want to search for best solution possible, you may find it useful to use heuristics that work faster, but allow for limited discrepancy from ideal solution.
For future answerers: Floyd-Warshall algorithm and all Floyd-like variations are inapplicable here.
In generally you should to strict bad variants...
I think you should use some variations of Branch_and_bound method
http://en.wikipedia.org/wiki/Branch_and_bound
Either bredth first search as norheim.se said or Dijkstra's algorithm would be my suggestion as well.
This sounds Travelling Salesman-esque? One solution is to use an optimisation technique such as an evolutionary algorithm. Currently you are doing an exhaustive search, which will get very slow very quickly. But I think this is pretty much a travelling salesman problem and it has been tackled for several decades if not centuries, and such there are several possible ways of attack. Google is your friend.
Perhaps this is what the original poster means by "iterating through each possibility manually and storing the shortest path", but I thought I'd like to make explicit what appears to be a baseline solution.
Assume you already have a two-point shortest path algorithm--this has classical solutions for various kinds of graphs. Assume all distances are nonnegative and d(A->B->C) = d(A->B) + d(B->C).
The essentials are that the path starts at S goes through one of intermediate cities "abcd" and ends with E:
e.g. SabcdE, SacbdE, etc...
With only 4 intermediate cities, you enumerate all 24 permutations. For each permutation use your shortest two-point algorithm to compute the path from head to tail, and its total distance.
Then given the start and ending point, there are 12 possibilities attaching to one of abcd and for each two possibilities for the interior. You've computed these distances already, so you add on the distance from S to the head and the tail to E. Choose minimum. So once you've precomputed the intermediate distances for a fixed set of interior cities you need to do 12 two point shortest path problems for any pair of start and end points.
This obviously scales poorly with increasing number of intermediate cities. It's not clear to me that it could do better unless you impose greater restrictions on the graph structure (is this in a physical Euclidenan space? Triangle inequality?).
My thought example: suppose all intermediate distances between cities are O(1). With no restriction on the graph, then the distance from S to any intermediate city might be 1000 except for one being 1. Same for the tail. So you can force the first city to be visited to be anything. Now, go one layer down, take the first city as the "start point". Apply the same argument: you can make the best path go to any of the following cities by manipulating the distances in the graph.
So it seems that the complexity can't be helped without additional assumptions.
This is the very common and real time situation any one can fall in.Google map user interface gives you the path in the same order, you add in the destination list. it doesn't give you the optimal path though their own Google maps API provide the solution.
Google maps API provides the solution for this. In the request to find out the path you have to provide the flag 'optimizeWaypoints: true,'. The request will seem like this.
var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
and you can see whole code of the utility in the view source as complete utility is developed in javascript and HTML.
I hope it will help.
It appears that the edges of your graph are bidirectional. In this case, the algorithm you're looking for is Dijkstra's algorithm.

Resources