When I have a graph with weights and a random generator how can I select some edges more desirable? I have a constraint of x weight and I need a formula that includes x weight and let me choose the next edge and so on. For example I have 4 edges with weight 5,10,15,20. How can I make the edge with weight 5 more desirable with a random generator but also when I have already choose edge 5 I need not choose edge with weight 20 because it exceeds my constraint.
Share
By defining the probability that one particular edge be selected as:
This will make edges with a low weight more likely to be selected, and edges with a weight bigger than the “constraint”, x, impossible to select.
Assuming that the RNG (random number generator) produces values between 0 and 1, the process to decide if a given edge should be selected is to draw a random number and see if it is less or equal to the probability as computed in the formula.
Depending on you specific needs, you could alter the formula slightly, for example by introducing a small factor that would prevent an edge with weight 0 to be systematically selected (by introducing a residual chance that it wouldn’t be selected), and conversely to prevent edges with a higher than “constraint” x edge value of never being selected.
Now… the above discusses the way of assigning probability to decide if a given edge should be selected. This is quite sufficient if indeed the program logic has a way of picking individual edges and simply asks itself the simple question “Should this particular edge be selected?”. However the program logic may have come up with a list of edges (which could be the complete collection of edges) and want to answer a more complicated question: “Of these n edges which one should I select ?”.
I was about to explain how to go about this 2nd type of problem, but in reading -between the lines- of the various comments, I think I understand better the problem at hand…
Edit (after various clarifications in comments)
As suspected, the underlying problem is that of an optimization problem rather than one of probability (although in this instance, probabilities are used to direct the search into the solution space in a stochastic fashion).
Specifically, the problem is one of the many variations on the Capacitated Vehicle Routing Problem
Without knowing details of what specific parameters (or combination thereof) we are trying to optimize, I can only speak in broad terms, trying to answer one of the questions of the OP:
Is is ok to combine the probability associated with Weight with the probability associated with distance ?
In a nutshell, yes it is. A plain multiplication may do the trick, although I would like to suggest a formula akin to the following: