Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

cplex - cpleqp equivalent in docplex

We can use cplexqp command to find the minimum of a problem using Cplex in matlab. I am looking for an alternative in docplex.

Cplex vs Docplex

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

let me write the standard qpex1 example in docplex:

from docplex.mp.model import Model  

mdl = Model(name='qpex1')

#decision variables
x = {b: mdl.continuous_var(0,40,name="x"+str(b)) for b in range(0,3)}


# Constraint
mdl.add_constraint( - x[0] +     x[1] + x[2] <= 20, 'ct1')
mdl.add_constraint(x[0] - 3 * x[1] + x[2] <= 30,'ct2');
# Objective
mdl.maximize(x[0] + 2 * x[1] + 3 * x[2]-
             0.5 * ( 33*x[0]*x[0] + 22*x[1]*x[1] + 11*x[2]*x[2] -
                     12*x[0]*x[1] - 23*x[1]*x[2] ))

msol=mdl.solve()

# Dislay solution
for v in mdl.iter_continuous_vars():
   print(v," = ",v.solution_value)

print("objective : ",msol.get_objective_value() ) 

which gives

x0  =  0.13911493492690713
x1  =  0.5984654737750436
x2  =  0.8983957227089207
objective :  2.0156165232891574

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...