1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import cplex
LP_problem = cplex.Cplex()
LP_problem.objective.set_sense(LP_problem.objective.sense.maximize)
var_name = ["x1", "x2", "x3"]
obj_parameters = [2.0, 6.0, 10.0]
x_upper_bound = [50.0, cplex.infinity, cplex.infinity]
x_lower_bound = [-cplex.infinity, 0.0, 0.0]
var_type = 'CCI' LP_problem.variables.add(obj=obj_parameters, ub=x_upper_bound, lb=x_lower_bound, types=var_type, names=var_name)
print("The lower limit of the value of the variable: ", LP_problem.variables.get_lower_bounds()) print("The upper limit of the value of the variable: ", LP_problem.variables.get_upper_bounds()) print("Variable Name: ", LP_problem.variables.get_names()) print("=========================================================\n")
senses = "LLE" rhs = [50.0, 20.0, 10.0] row_name = ["r1", "r2", "r3"] rows = [[["x1", "x2", "x3"], [2.0, 1.0, -2.0]], [["x1", "x2", "x3"], [1.0, -5.0, 0.0]], [["x1", "x2", "x3"], [0.0, 1.0, 2.0]]] LP_problem.linear_constraints.add(lin_expr=rows, senses=senses, rhs=rhs, names=row_name) LP_problem.solve()
print("\n=========================================================") print("Objective Function Values: ", LP_problem.solution.get_objective_value()) print("Optimal solution: ", LP_problem.solution.get_values())
|