Exemplo n.º 1
0
    def RestrictionLoad(self, vm_id, additional_constraints=[]):
        """
        Lexicografic order between two consecutive columns
        :param vm_id: the vm id
        :param additonal_constraints: other constraints
        :return:
        """
        print("Load vm ", vm_id, "combined=", additional_constraints)
        if len(additional_constraints) == 0:
            self.model.add_constraint(
                ct=sum([self.a[i, vm_id] for i in range(0, self.nr_comps)]) >=
                sum([self.a[i, vm_id + 1] for i in range(0, self.nr_comps)]),
                ctname="c_vm_load_lex_order")
        else:
            var = self.model.binary_var(
                name="vmload_VM{0}_combined".format(vm_id))
            if len(additional_constraints) == 1:
                self.model.add_equivalence(var, additional_constraints[0])
            else:
                self.model.add_equivalence(
                    var, LogicalAndExpr(additional_constraints))
            self.model.add_indicator(
                var,
                sum([self.a[i, vm_id] for i in range(0, self.nr_comps)]) >=
                sum([self.a[i, vm_id + 1] for i in range(0, self.nr_comps)]))

        return sum([self.a[i, vm_id] for i in range(self.nr_comps)]) == \
               sum([self.a[i, vm_id + 1] for i in range(self.nr_comps)])
Exemplo n.º 2
0
    def RestrictionLex(self, vm_id, additional_constraints=[]):
        """
        Lexicografic order between two consecutive columns
        :param vm_id: the vm id
        :param additonal_constraints: other constraints
        :return:
        """
        l = additional_constraints.copy()
        previousVar = None

        # print("self.nrComp ", self.nrComp)
        for i in range(0, self.nrComp):
            if i > 0:
                u = i - 1
                if previousVar is None:
                    l = []
                else:
                    l = [previousVar]
                l.append(self.a[u, vm_id] == self.a[u, vm_id + 1])
            var = self.model.binary_var(
                name="lex_VM{0}_comp{1}".format(vm_id, i))
            element = [self.a[i, vm_id] >= self.a[i, vm_id + 1]]
            if len(l) >= 1:
                if len(l) == 1:
                    self.model.add_equivalence(var, l[0])
                else:
                    self.model.add_equivalence(
                        var,
                        LogicalAndExpr(self.model, l) == 1)
                self.model.add_indicator(
                    var, self.a[i, vm_id] >= self.a[i, vm_id + 1])
                previousVar = var
            else:
                self.model.add_constraint(
                    ct=self.a[i, vm_id] >= self.a[i, vm_id + 1])
Exemplo n.º 3
0
 def new_logical_and_expr(self, bvars):
     # assume bvars is a sequence of binary vars
     nb_args = len(bvars)
     if not nb_args:
         return self.new_one_expr()
     elif 1 == nb_args:
         return bvars[0]
     else:
         return LogicalAndExpr(self._model, bvars)
Exemplo n.º 4
0
 def new_logical_and_expr(self, bvars):
     # assume bvars is a sequence of binary vars
     nb_args = len(bvars)
     if not nb_args:
         return self._new_constant_expr(cst=1, safe_number=True)
     elif 1 == nb_args:
         return bvars[0]
     else:
         return LogicalAndExpr(self._model, bvars)
Exemplo n.º 5
0
    def RestrictionPrice(self, vm_id, additional_constraints=[]):
        """
        Lexicografic order between two consecutive columns
        :param vm_id: the vm id
        :param additonal_constraints: other constraints
        :return:
        """
        print("Price vm ", vm_id, "combined=", additional_constraints)
        if len(additional_constraints) == 0:
            self.model.add_constraint(
                ct=self.PriceProv[vm_id] >= self.PriceProv[vm_id + 1],
                ctname="price_order")
        else:
            var = self.model.binary_var(
                name="order_VM{0}_combined".format(vm_id))
            if len(additional_constraints) == 1:
                self.model.add_equivalence(var, additional_constraints[0])
            else:
                self.model.add_equivalence(
                    var, LogicalAndExpr(additional_constraints))
            self.model.add_indicator(
                var, self.PriceProv[vm_id] >= self.PriceProv[vm_id + 1])

        return self.PriceProv[vm_id] == self.PriceProv[vm_id + 1]