Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
1

How to solve a combined problem of IP, Boolean Satisfiability and Maximization?

asked 4 years ago

ThemePark gravatar image

updated 4 years ago

I have a problem in mind that I want to solve, and after doing some research I believe it is a maximization problem that uses both Integer Programming and Boolean Satisfiability.

Now, it's easy enough for me to declare the variables, and assign them a range. But I simply don't know how to go on from there with Sage. So I was hoping that if I explain a thought up example of what I need to do, someone could point me in the right direction.

So I have some sum equations with a lot of variables, and all of the variables are positive integers, including zero. For example, one such equation could be like this:

(A or B) + (C or D or E)=10

This means, that at LEAST one combination of the variables in those two groups must sum up to 10. It could for example be A+C, B+D, A+E, but A+B doesn't matter. And there could be more than one combination thereof that sums up to 10, that also doesn't matter, just whether there's at least one that does.

Now I combine the sum equations I have, into groups, which is where the Boolean part comes in. Any such group can either be true or false. True, if all the sum equations can be solved, i.e. at least one combination in the equation sums up to the desired number. False, if even one of the equations cannot be solved.

So one such group could consist of two equations:

(A or B) + (C or D or E)=10

(A or D) + (B or E)=10

Because I have a lot of different variables, and a lot of equations, I doubt all the groups I will need to make, can all be solved, i.e. all are true. And that is where the Maximization problem comes in. The problem I actually need to solve, is to make as many as the aforementioned groups of equations True. Once I know this, and which groups and thus equations can be solved, I have my solution. And if there are more than one way to achieve the maximum number of solved groups, all those count and are of interest to me.

So this is where I'm at, with a problem I want to solve, and no idea on how to go about solving it with Sage.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 4 years ago

Max Alekseyev gravatar image

updated 4 years ago

For technical details on solving MILP in Sage and examples, you can refer to the documentation.

As for your specific problem, let us enumerate all clauses appearing in the equations in arbitrary order. For each variable Q present in clause number i, let's introduce a binary indicator variable sQ,i telling whether variable Q is taken from this clause. Also, let tQ,i be an integer variable with the value QsQ,i, which is enforced by the constraints: {tQ,iQL(1sQ,i),tQ,iQ+L(1sQ,i),tQ,iLsQ,i,tQ,iLsQ,i, where L is a large positive constant (larger than the maximum possible value for |Q|).

Now, without loss of generality, suppose that the clauses (A or B) and (C or D or E) in the equation (A or B) + (C or D or E)=10 have numbers 1 and 2, respectively. Then in addition to the above 4 inequalities for each pair (Q,i){(A,1),(B,1),(C,2),(D,2),(E,2)}, we introduce the following constraints: {sA,1+sB,1=1,sC,2+sD,2+sE,2=1,tA,1+tB,1+tC,2+tD,2+tE,2=10.() Here the first two constraints enforce that only one variable is taken from each clause, while the constraint () represents the equation itself.

Finally, to deal with the groups of equations, let's enumerate them, and for a group number j let's introduce a binary indicator variable pj telling whether the group is satisfied. Suppose that the group formed by equations (A or B) + (C or D or E)=10 and (A or D) + (B or E)=10 has number 1. Then we replace the equation labeled () above, which corresponds to the first equation, with {tA,1+tB,1+tC,2+tD,2+tE,210M(1p1),tA,1+tB,1+tC,2+tD,2+tE,210+M(1p1) and similarly for the second equation in the group, where M is a large positive constant (larger than the maximum absolute value of the l.h.s. of the equations).

The objective function to maximize is jpj, which gives the number of satisfied groups of equations.

Preview: (hide)
link

Comments

Alright, so before I posted this question, I had a look around the forum, and I noticed that a lot of commenters posted code as answers. So it threw me back that you decided to post math instead, and I've had to use some time to digest it all, as it's been a long time since I've had to deal with that notation.

I understand that the constants L and M are either zero, or their value, because you substract binary variables from 1. But I don't understand how choosing two large constants help enforce the constraints in those equations.

Also, since the s variable is binary, what happens if SC,2 and SE,2 are both 1? Because as I said, I need at least one combination to equal the sum, but not exactly one, there CAN be more.

Finally, I'm not sure how ...(more)

ThemePark gravatar imageThemePark ( 4 years ago )

Math is needed to solve the problem. My answer explains how to approach your problem. If you concern about actual Sage code, you'd need to give a particular example of the problem for illustration.

Constants L and M are not zero -- they must be large positive constants. Perhaps, you meant them multiplied by a coefficients, which may be 0 or 1. The idea is that whenever these constants come in the inequality with coefficient 1, the corresponding inequality becomes silent (i.e., automatically satisfied).

Both sC,2 and sE,2 cannot be 1 at the same time, because they must satisfy the constraint sC,2+sD,2+sE,2=1. But there may exist one solution, say, with sC,2=1 and sD,2=sE,2=0, and another solution with sE,2=1 and sC,2=sD,2=0.

Max Alekseyev gravatar imageMax Alekseyev ( 4 years ago )

Overall, your question makes an impression that you have trouble with formalizing/posing your problem as MILP (which is quite irrelevant to Sage), and this is what my answer explains how to do. As soon as your problem is formalized as MILP, it can be solved with Sage or any other solver (e.g., CPLEX, Gurobi, etc.).

If you have troubles with Sage specifically within the context of your problem, please let me know what they are.

Max Alekseyev gravatar imageMax Alekseyev ( 4 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 4 years ago

Seen: 344 times

Last updated: Mar 12 '21