Three random choices in limitations

  • Thread starter Thread starter Pattielli
  • Start date Start date
  • Tags Tags
    Choices Random
AI Thread Summary
The discussion revolves around generating three integer values (x, y, z) that satisfy specific conditions after randomly selecting three other integers (a, b, c) within a defined range. Participants emphasize the importance of ensuring that the sum of y and z equals x, while also adhering to constraints where x is less than a, y is less than b, and z is less than c. The conversation touches on the challenges of implementing this logic in programming languages like C++, Java, and VB, particularly regarding the use of loops and random number generation. Additionally, there is a focus on creating a flow matrix that meets the criteria of Kirchhoff's law, ensuring that flow values are randomly chosen yet remain within the limits set by a corresponding capacity matrix. The thread concludes with a request for further guidance on effectively implementing these concepts in code.
Pattielli
Messages
296
Reaction score
0
I have six integer numbers and let's call them x,y,z,a,b and c.
All of them are to be in the [1,30] domain and satisfy the following conditions:

x=y+z

x<a , y<b , z<c

Now, if I start by "choosing a,b and c randomly first", Would you please tell me how I can randomly pick out the next three numbers (x,y,z) which still satisfy what I already mention above ?

Thank you very much,
 
Computer science news on Phys.org
This is the same as Kirchoff law in Electrics ? Please help me...
Go_in=go_out1+go_out2+...go_outn
 
Randomly generate a,b, and c

test that a \geq b+c

if the above condition isn't true then x<a, y<b, z<c when x=y+z will never be true and will put your program into an endless loop.

Once you have 'a', 'b', and 'c' values that meets the conditions you can then randomly generate the 'x' , 'y', and 'z' values. Generate an 'y' value within a while loop and test to see if it meets the criteria of being less than 'b'. If it does then exit the loop. Same for 'z'. Once you have a 'y' and 'z' you can then simply add them and store the result into 'x'.

I don't know which language you're using so I can't tell you exactly how to do the above. Each language does things differently (loops are pretty standard though) so you'll have to figure the specifics out on your own. It's not that tough.

Well, good luck.
 
Last edited:
Another clearification:

Code:
a--fa/ca-->b--fb/cb-->...
|          |
x--fx/cx-->y--fy/cy-->...
ca,cb,cx,cy are all known in advance and they capacities fi are all flows. Now i have to generate flows randomly and this "random_ness" blocks my way...
All of the capacities are stored in a vector and I already have a network...
Now you already see how it is...please give me some hints...
Thank you,
 
Thank faust very much for your help,
I can code in java, vb but I haven't used them for long...
I like C/C++ and now I am solving this networkflow problem in C++.
I think I can manage to make a success with rand() function and do as what you told me but the problem is that I can't check the next move of the loop and randomize the x,y,z to satisfy the condition..
For example, below is my network
Code:
0  1  1  0
0  0  1  1
0  0  0  1
0  0  0  0
and here is my capacity matrix
Code:
0  12  21  0
0   0   1   2
0   0   0   1
0   0   0   0

Again Thank you
 
I still have not been able to make it work...Help me please ?
 
I don't understand what exactly you are trying to do. Where exactly are you having a problem? Is it the generation of random values that is troubling you or are you having trouble generating randome values that meet your criteria?
 
I nowwould like to make a matrix of flows that satisfies the above conditions, each flow value will be randomly chosen. And that is the problem i am having, flow value=1~20 and smaller than cappacity on each equivalent edge
 
Pattielli said:
Thank faust very much for your help,
I can code in java, vb but I haven't used them for long...
I like C/C++ and now I am solving this networkflow problem in C++.
I think I can manage to make a success with rand() function and do as what you told me but the problem is that I can't check the next move of the loop and randomize the x,y,z to satisfy the condition..
For example, below is my network
Code:
0  1  1  0
0  0  1  1
0  0  0  1
0  0  0  0
and here is my capacity matrix
Code:
0  12  21  0
0   0   1   2
0   0   0   1
0   0   0   0

Again Thank you

Ok, I still don't know how you are using these matrices. Also, where are you having a problem? Are you having trouble generating and testing the variables or are you having trouble filling you arrays once you create your variable? How does the new criteria affect the variable tests? are you still bounded by the same criteria which you initially stated?
 
  • #10
Thank you,
As I already said, I used 2d vectors for storing these matrices..
Look at the capacity matrix, I now have to create another one and represent it as a flow matrix whose values are all randomly chosen between 1-20 and must satisfy the "Kirchoff" law (in=out), and that each element in flow matrix must be smaller than that in the capacity matrix (in an equivalent position I mean)...This is the way i am thinking of how to create this flow matrix, but if you have any other way to make this work and are willing to let me know, I will thank you very very much...

Do you have any instructions? Please help...
 
Back
Top