For example, the solution for gurobi has two solutions, as follows: [10,20,50,70] [55,79,30,80] I only want to output solutions that contain only multiples of 10. The sample example as follow:

m = Model()
R = list(range(0,6)) 

# Adding variables
z = m.addVars(6, lb=1, ub=100, vtype=GRB.INTEGER)

m.addConstr(z.prod([1,1,1,1,1,1]) == 100, name="")

m.setObjective(z.prod([1,1,1,1,1,1]), sense=GRB.MAXIMIZE)

This program has many solutions, But I just want to output the solution for multiples of 10,like[10,10,20,30,20,10]. Please tell me how do I get the solution.Thank you very much!

  • 1
    $\begingroup$ Here is a simple change of variable. Set the domain of a variable x as (non-negative) integers. Use 10x instead of just x to define the model. Solve for x. Then, 10x is your answer. $\endgroup$ Jun 30 at 1:25
  • $\begingroup$ I can achieve results with the method you mentioned. But I have another question,If I want to use the elements of the list as the range of the solution, like``` list1 = [10,20,50,60,30]```,and the elements of the solution must belong to the elements of the list.How should this be achieved? $\endgroup$
    – Zying
    Jun 30 at 2:10
  • $\begingroup$ Best is to use a binary variable associated with each element of the list and then do the same thing Qurious Cube said. $\endgroup$
    – Richard
    Jun 30 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.