0

I have developed a linear program and implemented it in Python via docplex. I would like to know how one can print the dual model using docplex? I have seen similar posts for other programming languages, but I was unable to find relevant discussions for docplex.

How can I export dual model from Cplex using java?

mdslt
  • 155
  • 1
  • 10

1 Answers1

1

I would use cplex command line from python through an external call.

If I use the zoo example

import os

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.continuous_var(name='nbBus40')
nbbus30 = mdl.continuous_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)

mdl.solve(log_output=True,)

mdl.export("buses.lp")



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

os.system("cplex -c \"read buses.lp\" \"write buses.dua\"")

then in buses.dua I get

NAME          buses.lp.dual
ROWS
 N  rhs     
 G  nbBus40 
 G  nbBus30 
COLUMNS
    kids      rhs                          -300
    kids      nbBus40                       -40
    kids      nbBus30                       -30
RHS
    obj       nbBus40                      -500
    obj       nbBus30                      -400
ENDATA

which gives in lp format

Minimize
 rhs: - 300 kids
Subject To
 nbBus40: - 40 kids >= -500
 nbBus30: - 30 kids >= -400
End
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • 1
    It seems that the primal problem was printed in the buses.dua file unless I am not correctly reading this file. – mdslt Sep 07 '22 at 15:27