def test_pulp_022(self): # Initial value prob = LpProblem("test022", const.LpMinimize) x = LpVariable("x", 0, 4) y = LpVariable("y", -1, 1) z = LpVariable("z", 0, None, const.LpInteger) prob += x + 4 * y + 9 * z, "obj" prob += x + y <= 5, "c1" prob += x + z >= 10, "c2" prob += -y + z == 7.5, "c3" # if we give the actual optimal solution to CBC (x=3) # it returns a weird solution with mip_start x.setInitialValue(4) y.setInitialValue(-0.5) z.setInitialValue(7) self.solver.mip_start = True print("\t Testing MIP solution") if self.solver.__class__ in [COIN_CMD, PULP_CBC_CMD]: warnings.warn("CBC gives a wrong solution with mip start.") else: pulpTestCheck(prob, self.solver, [const.LpStatusOptimal], { x: 3, y: -0.5, z: 7 })
def test_pulp_022(self): # Initial value prob = LpProblem("test022", const.LpMinimize) x = LpVariable("x", 0, 4) y = LpVariable("y", -1, 1) z = LpVariable("z", 0, None, const.LpInteger) prob += x + 4 * y + 9 * z, "obj" prob += x + y <= 5, "c1" prob += x + z >= 10, "c2" prob += -y + z == 7.5, "c3" x.setInitialValue(3) y.setInitialValue(-0.5) z.setInitialValue(7) if self.solver.name in ["GUROBI", "GUROBI_CMD", "CPLEX_CMD", "CPLEX_PY"]: self.solver.optionsDict["warmStart"] = True print("\t Testing Initial value in MIP solution") pulpTestCheck(prob, self.solver, [const.LpStatusOptimal], {x: 3, y: -0.5, z: 7})
def test_pulp_022(self): # Initial value prob = LpProblem("test022", const.LpMinimize) x = LpVariable("x", 0, 4) y = LpVariable("y", -1, 1) z = LpVariable("z", 0, None, const.LpInteger) prob += x + 4 * y + 9 * z, "obj" prob += x + y <= 5, "c1" prob += x + z >= 10, "c2" prob += -y + z == 7.5, "c3" x.setInitialValue(3) y.setInitialValue(-0.5) z.setInitialValue(7) if self.solver.name in ['GUROBI', 'GUROBI_CMD', 'CPLEX_CMD', 'CPLEX_PY']: warnings.warn("CBC gives a wrong solution with warmStart.") self.solver.optionsDict['warmStart'] = True print("\t Testing MIP solution") pulpTestCheck(prob, self.solver, [const.LpStatusOptimal], {x: 3, y: -0.5, z: 7})
def init_one(a: pulp.LpVariable, b: float) -> None: a.setInitialValue(b)