Algorithm for finding connected subgraph of a vertex weighted graph with a sum close to a given value -


given vertex weighted graph g (depicted below), vertex v graph , integer value x, there known algorithm finding connected sub graph of g such target vertex in sub graph , sum of weights of sub graph close x possible? moreover, if exact match of x cannot found, algorithm should still return sub graphs closest x possible.

some examples given graph below:

v = f, x = 12. a,b,f,i , f,g,c,d solutions.

v = c, x = 16. c,d,e,h solution.

vertex weighted simple graph.

finding solution looks variant of knapsack problem me, additional constraint items in knapsack must form connected graph.

one approach check possible subgraphs containing v , searching maximum weight (up x):

you use kind of greedy algorithm, starting node v , adding 1 adjacent node after another, keeping track of total subgraph weight. if reach x, finished, if overshoot x, must backtrack , select other nodes subgraph. during whole algorithm, keep track of "best" subgraph, if no exact solution found in end, still have best approximation.

you can choose order of nodes add subgraph utilizing heuristic, e.g. best fit, affects run time, not quality of results..


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -