Message Boards Message Boards

0
|
8511 Views
|
13 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Solve a large system of equations with 19 variables?

Posted 5 years ago
POSTED BY: Paul Cleary
13 Replies

Paul,

Shouldn’t your “or” operator be “and” (&&)? Don’t you want p2, p4, and p5 to all be less than p1? Or am I misreading your description?

Regards,

Neil

POSTED BY: Neil Singer
Posted 5 years ago
POSTED BY: Paul Cleary

Paul,

Yes, the &&'s are not needed.

As a side note, if you use && or || I like to use parenthesis -- && and || have a high precedence so you can get some strange results if the input can be interpreted two ways. So my practice is to always type (p1>p2)&&(p1>p4) In this case it is not needed but I've been burned by the case when the && operates on the two expression halves first.

Regards,

Neil

POSTED BY: Neil Singer
Posted 5 years ago
POSTED BY: Paul Cleary

If there are 19 variables, then why are there only 11 in your code and what does "..." mean?

Posted 5 years ago
POSTED BY: Paul Cleary
Posted 5 years ago
POSTED BY: Paul Cleary

I think I see part of the problem. Looking closely at your list of constraints there, you see instances like “p1 >= p2” and later “p2 >= p1”. That implies that “p1 == p2”, so a solution will only be found if that is true. There are a number of instances in your constraint set where equality is implied, even though you specified the constraints as >= inequalities. I am guessing that a result of this is that your constraint that all of the variables add to 58 is unsatisfiable, so the solver returns nothing. If I have time after I grab lunch, I might see if it becomes clearer if the system of equations is simplified by hand (e.g., manually replace pairs of constraints like p1 >= p2, p2 >= p1 with one constraint that p1 == p2.)

POSTED BY: Matthew Sottile

I looked more closely, and it is true - all of the inequalities can be reduced to {p1==p2, p2==p3, ..., p18==p19}, which means that a solution must assign the same value to all of the p's. The sum p1+p2+...+p19=58 is unsatisfiable if all of the variables must be equal and integers, since 58/19 is 3.05263, which isn't an integer. It looks like you aren't encoding your problem correctly as a set of constraints if you think it is possible to solve - as stated, the equations are not satisfiable.

POSTED BY: Matthew Sottile
Posted 5 years ago
POSTED BY: Paul Cleary

Paul,

It appears that your problem is "non-endogenous". Which means that your constraints depend on the values of the variables, pn. These are particularly hard problems to solve because the constraints change with the variables.

Can you solve the "stages" sequentially? Solve for p1, then use the value of p1 to solve for p2,p4,p5 and then from those values construct the constraints for the p2 dependencies -- or do the later solutions alter the earlier choices? For example, in your earlier example up to p7, how did you set p1=4? was that iterative until a complete solution was found?

If the later is the case you can try creating constraints that combine And and Or and enumerate all the possible constraint sets for each stage but that might get large and difficult to solve.

Regards,

Neil

POSTED BY: Neil Singer
Posted 5 years ago
POSTED BY: Paul Cleary
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract