I'm using IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer 22.1.2.0 (Academic Initiative) on Ubuntu 22.04.5 LTS with Python 3.10.12. The following is my Python code.
'''
import cplex
from cplex import Cplex
from docplex.mp.model import Model
import os, fileinput
milp_model = docplex.Cplex()
objective = 1.0
index = 0
while objective == 1.0:
milp_model.read("model.lp")
milp_model.solve()
objective = milp_model.solution.get_objective_value()
print("OBJECTIVE " + str(index) + ": " + str(objective) + "\n")
#print("VARIABLES: " + str(milp_model.solution.get_values()) + "\n")
if objective == 1.0:
for i in range(1,6):
variable_value = milp_model.solution.get_values("x" + str(i))
print("x" + str(i) + ": " + str(variable_value) + "\n")
if variable_value == 1.0:
for line in fileinput.FileInput("model.lp", inplace=True):
if "Binary" in line:
print("x" + str(i) + " = 0")
print(line, end = "")
'''
This code works in Community version, but not in Academic Initiative. It throws error message:
Traceback (most recent call last):
File "/home/insfornet/MILP/Cube_Permutation_3/main.py", line 1, in <module>
import cplex
ModuleNotFoundError: No module named 'cplex'
Please help. Thank you.
------------------------------
Kok-An Pang
------------------------------