Beispiel #1
0
 def add_variables(self, variables, variable_types,
                   obj_coeff, variable_names, variable_ranges):
     assert all((v not in self._variable_idx for v in variables))
     if not variable_names:
         variable_names = [ util.fmt_var(v) for v in variables ]
     else:
         assert len(variable_names) == len(variables)
     if not variable_ranges:
         variable_lb = []
         variable_ub = []
     else:
         assert len(variable_ranges) == len(variables)
         variable_lb = [ r[0] for r in variable_ranges ]
         variable_ub = [ r[1] for r in variable_ranges ]
     [ self._variable_idx[v] for v in variables ]
     self._c.variables.add(obj=   obj_coeff,
                           types= [ CplexSolver.TYPE_MAPPING[vt] for vt in variable_types ],
                           lb=    variable_lb,
                           ub=    variable_ub,
                           names= variable_names)
     return None
Beispiel #2
0
 def add_variables(self, variables, variable_types,
                   obj_coeff, variable_names, variable_ranges):
     assert all((v not in self._variable_idx for v in variables))
     if not variable_names:
         variable_names = [ util.fmt_var(v) for v in variables ]
     else:
         assert len(variable_names) == len(variables)
     if not variable_ranges:
         variable_lb = [ 0.0 ] * len(variables)
         variable_ub = [ gurobipy.GRB.INFINITY ] * len(variables)
     else:
         assert len(variable_ranges) == len(variables)
         variable_lb = [ r[0] for r in variable_ranges ]
         variable_ub = [ r[1] for r in variable_ranges ]
     for i,v in enumerate(variables):
         self._variable_idx[v] = self._m.addVar(
             lb=    variable_lb[i],
             ub=    variable_ub[i],
             vtype= GurobiSolver.TYPE_MAPPING[variable_types[i]],
             name=  variable_names[i])
         if obj_coeff[i] > 0.0 or obj_coeff[i] < 0.0:
             self._objs.append((obj_coeff[i], self._variable_idx[v]))
     self._m.update()
     return None