Exemple #1
0
    def test_pulp_075(self):
        # Column Based modelling of test_pulp_1 with empty constraints
        prob = LpProblem("test075", const.LpMinimize)
        obj = LpConstraintVar("obj")
        # constraints
        a = LpConstraintVar("C1", const.LpConstraintLE, 5)
        b = LpConstraintVar("C2", const.LpConstraintGE, 10)
        c = LpConstraintVar("C3", const.LpConstraintEQ, 7)

        prob.setObjective(obj)
        prob += a
        prob += b
        prob += c
        # Variables
        x = LpVariable("x", 0, 4, const.LpContinuous, obj + b)
        y = LpVariable("y", -1, 1, const.LpContinuous, 4 * obj - c)
        z = LpVariable("z", 0, None, const.LpContinuous, 9 * obj + b + c)
        if self.solver.__class__ in [
                CPLEX_DLL, CPLEX_CMD, COINMP_DLL, YAPOSIB, PYGLPK
        ]:
            print("\t Testing column based modelling with empty constraints")
            pulpTestCheck(prob, self.solver, [const.LpStatusOptimal], {
                x: 4,
                y: -1,
                z: 6
            })
 def generate_xtreme_point(self):
     obj = LpConstraintVar()
     for v in self.prob.variables():
         obj.addVariable(v, self.piCurrent[v.name])
     self.prob.setObjective(obj)
     self.prob.solve()
     #solvers.COIN_CMD.solve(self.prob)
     for v in self.var:
         self.currentXtremePoint[v] = self.var[v].value()
     if self.output == 1:
         currentXtremePointList = self.currentXtremePoint.items()
         currentXtremePointList.sort()
         for v in currentXtremePointList:
             print v[0]+'\t', v[1]
     self.extremePoints.append(self.currentXtremePoint.values())
     return self.prob.objective.value()
Exemple #3
0
 def generate_xtreme_point(self):
     obj = LpConstraintVar()
     for v in self.prob.variables():
         obj.addVariable(v, self.piCurrent[v.name])
     self.prob.setObjective(obj)
     self.prob.solve()
     #solvers.COIN_CMD.solve(self.prob)
     for v in self.var:
         self.currentXtremePoint[v] = self.var[v].value()
     if self.output == 1:
         currentXtremePointList = self.currentXtremePoint.items()
         currentXtremePointList.sort()
         for v in currentXtremePointList:
             print v[0] + '\t', v[1]
     self.extremePoints.append(self.currentXtremePoint.values())
     return self.prob.objective.value()
Exemple #4
0
    def _formulate_master(self):
        """
        Formulate set covering formulation for aircraft recovery
        """
        # Variable dicts
        a_dict = {
            (s_label[1], s): s.cost for s_label, s in self.Data.scheds.items()
        }
        dum_dict = {
            f: 20000 + 20000 * (f.arrival - f.departure)
            for f in self.Data.flights
        }
        # CONSTRAINTS #
        # Generate empty >= constraints for all flights
        self.master.flight_constrs = {
            key: LpConstraintVar(key, LpConstraintGE, 1) for key in dum_dict
        }

        # Generate empty <= constraints for all aircraft
        self.master.assign_constrs = {
            k: LpConstraintVar(k, LpConstraintLE, 1) for k in self.Data.aircraft
        }
        # VARIABLES #
        # Create dummy variables for each flight
        dummy = {
            key: LpVariable(
                'dummy{0}'.format(key), 0, 1, LpBinary,
                lpSum(val * self.master.objective +
                      self.master.flight_constrs[key]))
            for key, val in dum_dict.items()
        }
        # Create assignment variables for each aircraft (and schedule)
        a = {
            key_tuple:
            LpVariable('a[{}]'.format(key_tuple), 0, 1, LpBinary,
                       lpSum(self.master.assign_constrs[key_tuple[0]]))
            for key_tuple, val in a_dict.items()
        }
        # Add flight constraints to model
        for constr in self.master.flight_constrs.values():
            self.master.model += constr
        # Add assignment constraints to the model
        for constr in self.master.assign_constrs.values():
            self.master.model += constr
        # Set objective function
        self.master.model.sense = LpMinimize
        self.master.model.setObjective(self.master.objective)
Exemple #5
0
    def test_pulp_070(self):
        # Column Based modelling of test_pulp_1
        prob = LpProblem("test070", const.LpMinimize)
        obj = LpConstraintVar("obj")
        # constraints
        a = LpConstraintVar("C1", const.LpConstraintLE, 5)
        b = LpConstraintVar("C2", const.LpConstraintGE, 10)
        c = LpConstraintVar("C3", const.LpConstraintEQ, 7)

        prob.setObjective(obj)
        prob += a
        prob += b
        prob += c
        # Variables
        x = LpVariable("x", 0, 4, const.LpContinuous, obj + a + b)
        y = LpVariable("y", -1, 1, const.LpContinuous, 4 * obj + a - c)
        z = LpVariable("z", 0, None, const.LpContinuous, 9 * obj + b + c)
        print("\t Testing column based modelling")
        pulpTestCheck(prob, self.solver, [const.LpStatusOptimal], {x: 4, y: -1, z: 6})
Exemple #6
0
    def test_pulp_090(self):
        # Column Based modelling of test_pulp_1 with a resolve
        prob = LpProblem("test090", const.LpMinimize)
        obj = LpConstraintVar("obj")
        # constraints
        a = LpConstraintVar("C1", const.LpConstraintLE, 5)
        b = LpConstraintVar("C2", const.LpConstraintGE, 10)
        c = LpConstraintVar("C3", const.LpConstraintEQ, 7)

        prob.setObjective(obj)
        prob += a
        prob += b
        prob += c

        prob.setSolver(self.solver)  # Variables
        x = LpVariable("x", 0, 4, const.LpContinuous, obj + a + b)
        y = LpVariable("y", -1, 1, const.LpContinuous, 4 * obj + a - c)
        prob.resolve()
        z = LpVariable("z", 0, None, const.LpContinuous, 9 * obj + b + c)
        if self.solver.__class__ in [CPLEX_DLL, COINMP_DLL]:
            print("\t Testing resolve of problem")
            prob.resolve()
Exemple #7
0
    def __init__(self, Data):
        """
        Formulate the master problem.

        Parameters
        ----------
        Data : object,
            classes.Data object with problem data.
        """
        self.Data = Data
        self.master = Expand()
        # Init lp relaxation of the master problem
        self.relax = Expand()
        # Init master problem with empty constraints and objective
        self.master.model = LpProblem("master problem")
        self.master.objective = LpConstraintVar("obj")
        # Container for flight constraints
        self.master.flight_constrs = {}
        # Container for assignment constraints
        self.master.assign_constrs = {}

        self._formulate_master()