Example #1
0
 def _create_using(self, model, **kwds):
     #
     # Clone the model
     #
     M = model.clone()
     #
     # Iterate over the expressions in all objectives and constraints, replacing fixed
     # variables with their associated constants.
     #
     for ctype in [Objective, Constraint]:
         for obj in M.component_map(Objective).values():
             for name in obj:
                 if not obj[name].expr is None:
                     obj[name].expr = self._fix_vars(obj[name].expr, model)
     #
     # Iterate over variables, omitting those that have fixed values
     #
     ctr = 0
     for i in sequence(M.nvariables()):
         var = M.variable(i)
         del M._var[i - 1]
         if var.fixed:
             if var.is_binary():
                 M.statistics.number_of_binary_variables -= 1
             elif var.is_integer():
                 M.statistics.number_of_integer_variables -= 1
             elif var.is_continuous():
                 M.statistics.number_of_continuous_variables -= 1
             M.statistics.number_of_variables -= 1
             del M._label_var_map[var.label]
             del var.component()._data[var.index]
         else:
             M._var[ctr] = var
             var._old_id = var.id
             var.id = ctr
             ctr += 1
     return M
Example #2
0
 def _create_using(self, model, **kwds):
     #
     # Clone the model
     #
     M = model.clone()
     #
     # Iterate over the expressions in all objectives and constraints, replacing fixed
     # variables with their associated constants.
     #
     for ctype in [Objective, Constraint]:
         for obj in M.component_map(Objective).values():
             for name in obj:
                 if not obj[name].expr is None:
                     obj[name].expr = self._fix_vars(obj[name].expr, model)
     #
     # Iterate over variables, omitting those that have fixed values
     #
     ctr = 0
     for i in sequence(M.nvariables()):
         var = M.variable(i)
         del M._var[ i-1 ]
         if var.fixed:
             if var.is_binary():
                 M.statistics.number_of_binary_variables -= 1
             elif var.is_integer():
                 M.statistics.number_of_integer_variables -= 1
             elif var.is_continuous():
                 M.statistics.number_of_continuous_variables -= 1
             M.statistics.number_of_variables -= 1
             del M._label_var_map[ var.label ]
             del var.component()._data[ var.index ]
         else:
             M._var[ ctr ] = var
             var._old_id = var.id
             var.id = ctr
             ctr += 1
     return M