1

Imagine the following equations:

2x + 3y + 4z + 5q = 32
x + y + z + q = 8

All variables are integers and have some constraints like

0 <= x <= xMax
0 <= y <= yMax
0 <= z <= zMax
0 <= q <= qMax

I know this has multiple solutions. How would you pick RANDOMLY one of the solutions without using brute-force?

mtet88
  • 524
  • 6
  • 21
  • Could you elaborate on picking randomly? Do you mean pick a random number for x, y, z, q and test it? – Jim Jeffries Apr 10 '15 at 09:38
  • That would be more the brute-force approach which is actually what I want to avoid... what I mean is to get a different solution each time... @Henrik yes, sorry about that... fixed – mtet88 Apr 10 '15 at 09:42
  • Well... you'll have to find all the solutions and then pick one randomly... – Lior Kogan Apr 10 '15 at 09:58
  • and how would you generate all the solutions? – mtet88 Apr 10 '15 at 10:05
  • Usually one will use an integer linear programming solver with a dummy variable as the optimization goal (to get all solutions). See for example http://www.aiexp.info/calculating-all-feasible-solutions-of-ilp.html – Lior Kogan Apr 10 '15 at 11:13

1 Answers1

0

I found another approach to solve this. The original problem was to find a generic non-brute-force way to create an exam out of a pool of questions.

There were 4 types of questions

x, y, z, q

I had to randomly pick exactly 8 question

x + y + z + q = 8

Each type of question had a different score AND the total score of the picked questions had to be 32

2x + 3y + 4z + 5q = 32    

If someone is interested you can find the solution here

Thanks for your help anyways :)

Community
  • 1
  • 1
mtet88
  • 524
  • 6
  • 21