Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using branch priority in Pyomo #1587

Closed
ZedongPeng opened this issue Aug 10, 2020 · 4 comments
Closed

Using branch priority in Pyomo #1587

ZedongPeng opened this issue Aug 10, 2020 · 4 comments

Comments

@ZedongPeng
Copy link
Contributor

ZedongPeng commented Aug 10, 2020

I am trying to set branch priority in Pyomo for the MILP model.
I noticed that branch priority in cplex is available. #1300 and #1299

There is an example on overstackflow.

m = ConcreteModel()
m.x = Var(domain=Integers)
m.s = RangeSet(10)
m.y = Var(m.s, domain=Integers)
m.o = Objective(expr=m.x + sum(m.y), sense=minimize)
m.c = Constraint(expr=m.x >= 1)
m.c2 = Constraint(expr=quicksum(m.y[i] for i in m.s) >= 10)

m.priority = Suffix(direction=Suffix.EXPORT, datatype=Suffix.INT)
m.direction = Suffix(direction=Suffix.EXPORT, datatype=Suffix.INT)  # this is optional

m.priority.set_value(m.x, 1)

m.priority.set_value(m.y, 2)
m.direction.set_value(m.y, BranchDirection.down)

m.direction.set_value(m.y[10], 1)

with SolverFactory('cplex', solver_io='lp') as opt:
    opt.solve(model, priorities=True)

Since this example is small. I can't check the detailed branch process of cplex. However, there is an warning reported by cplex.

CPLEX> Warning, line 3: '1' is not a variable.
Priority order '/var/folders/pj/1113b24j7b3083zbt19pjxqm0000gn/T/tmpjzaw3lvp.cplex.ord' read.

It looks like the priority of m.x is not set successfully.
The m.direction suffix is optional, so I removed it. There are more warnings in the output.

CPLEX> Warning, line 3: '1' is not a variable.
Warning, line 4: '2' is not a variable.
Warning, line 5: '2' is not a variable.
Warning, line 6: '2' is not a variable.
Warning, line 7: '2' is not a variable.
Warning, line 8: '2' is not a variable.
Warning, line 9: '2' is not a variable.
Warning, line 10: '2' is not a variable.
Warning, line 11: '2' is not a variable.
Warning, line 12: '0' is not a variable.
Warning, line 13: '1' is not a variable.
Warning: No priority order values read or loaded.
Priority order '/var/folders/pj/1113b24j7b3083zbt19pjxqm0000gn/T/tmpa28cz_1d.cplex.ord' read.

It looks like if m.direction is not set, m.priority will fail. Is this reasonable?

I also tested the priority suffix in a bigger MILP model.

# mastermodel is defined as a MILP model
# priority setting
mastermodel.priority = Suffix(direction=Suffix.EXPORT, datatype=Suffix.INT) 
mastermodel.direction = Suffix(direction=Suffix.EXPORT, datatype=Suffix.INT)

mastermodel.priority.set_value(mastermodel.y_drill, 1) # y_drill is an indexed binary variable
mastermodel.direction.set_value(mastermodel.y_drill, BranchDirection.up)

mastermodel.priority.set_value(mastermodel.y_rtp, 2) # y_rtp is an indexed binary variable
mastermodel.direction.set_value(mastermodel.y_rtp, BranchDirection.up)

with SolverFactory('cplex', solver_io='lp') as opt:
    opt.solve(mastermodel, priorities=True, tee=True)

I tried three cases:

  • without setting the priority suffix
  • set the priority of y_drill bigger than y_rtp
  • set the priority of y_rtp bigger than y_drill

In all three examples, the branch process of cplex is the same according to the output.

Is there any other example I can refer to for branch priority in Pyomo?

Thanks.

@ruaridhw
Copy link
Contributor

ruaridhw commented Nov 9, 2020

@ZedongPeng, this is a good example of a bug. It looks like the direction suffix is not optional at all.

If you add

m.direction.set_value(m.x, BranchDirection.down)

to your example, it passes.

In all three examples, the branch process of cplex is the same according to the output.

As for this question, my understanding is that CPLEX uses the branching priorities you specify as a guide. Whether or not anything actually changes in the solver's routine is another matter. As long as the ord file is read successfully and in full, I don't know if it's possible to guarantee that it is obeyed.

@ZedongPeng
Copy link
Contributor Author

@ZedongPeng, this is a good example of a bug. It looks like the direction suffix is not optional at all.

If you add

m.direction.set_value(m.x, BranchDirection.down)

to your example, it passes.

In all three examples, the branch process of cplex is the same according to the output.

As for this question, my understanding is that CPLEX uses the branching priorities you specify as a guide. Whether or not anything actually changes in the solver's routine is another matter. As long as the ord file is read successfully and in full, I don't know if it's possible to guarantee that it is obeyed.

Thank you @ruaridhw a lot for the reply. I agree with you that direction suffix is required when priority is set.

@jsiirola
Copy link
Member

@ZedongPeng, as this does not appear to be a problem with Pyomo, are you ok if we close this issue?

@ZedongPeng
Copy link
Contributor Author

Sure. Thank you for the help. @jsiirola

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants