+
+
+ def get_row_count(self):
+ """
+ Return the number of rows in the constraint matrix.
+ """
+ return len(self.constraint_matrix)
+
+
+ def get_column_count(self):
+ """
+ Return the number of columns in the constraint matrix.
+ If we don't have any rows yet, claim zero columns as well.
+ """
+ if self.get_row_count() == 0:
+ return 0
+ else:
+ return len(self.constraint_matrix[0])
+
+
+
+ @property
+ def type(self):
+ """
+ A property representing the type of linear program, either
+ MINIMIZE or MAXIMIZE.
+ """
+ return self._type
+
+
+ def type(self, type):
+ if type == MINIMIZE:
+ self._type = MINIMIZE
+ if self._lp != None:
+ lpsolve('set_minim', self._lp)
+ else:
+ self._type = MAXIMIZE
+ if self._lp != None:
+ lpsolve('set_maxim', self._lp)
+
+
+
+ @property
+ def objective_coefficients(self):
+ return self._objective_coefficients
+
+
+ @objective_coefficients.setter
+ def objective_coefficients(self, value):
+ self._objective_coefficients = value
+
+ if self._lp != None:
+ lpsolve('set_obj_fn',
+ self._lp,
+ self._objective_coefficients)
+
+
+
+ @property
+ def constraint_matrix(self):
+ return self._constraint_matrix
+
+ @constraint_matrix.setter
+ def constraint_matrix(self, value):
+ self._constraint_matrix = value
+
+ if self._lp != None:
+ lpsolve('set_mat', self._lp, value)
+
+
+
+ @property
+ def rhs(self):
+ return self._rhs
+
+ @rhs.setter
+ def rhs(self, value):
+ self._rhs = value
+
+ if self._lp != None:
+ lpsolve('set_rh_vec', self._lp, self._rhs)
+
+
+
+ @property
+ def inequalities(self):
+ return self._inequalities
+
+ @inequalities.setter
+ def inequalities(self, value):
+ self._inequalities = value
+
+ if self._lp != None:
+ for i in range(self.get_row_count()):
+ lpsolve('set_constr_type', self._lp, i+1, value[i])
+
+
+ @property
+ def solution_lower_bounds(self):
+ return self._solution_lower_bounds
+
+ @solution_lower_bounds.setter
+ def solution_lower_bounds(self, value):
+ if len(value) != self.get_column_count():
+ return
+
+ self._solution_lower_bounds = value
+
+ if self._lp != None:
+ for i in range(self.get_column_count()):
+ lpsolve('set_lowbo', self._lp, i+1, value[i])
+
+
+
+ @property
+ def solution_upper_bounds(self):
+ return self._solution_upper_bounds
+
+
+ @solution_upper_bounds.setter
+ def solution_upper_bounds(self, value):
+ if len(value) != self.get_column_count():
+ return
+
+ self._solution_upper_bounds = value
+
+ if self._lp != None:
+ for i in range(self.get_column_count()):
+ lpsolve('set_upbo', self._lp, i+1, value[i])
+
+
+
+ @property
+ def integer_variables(self):
+ """
+ A vector containing the indices of any solution variables
+ which must be integers.
+ """
+ return self._integer_variables
+
+ @integer_variables.setter
+ def integer_variables(self, value):
+ self._integer_variables = value
+
+ if self._lp != None:
+ for i in range(len(value)):
+ lpsolve('set_int', self._lp, value[i], 1)
+
+
+
+ def make_all_variables_integers(self):
+ """
+ Force all solution variables to be integers. This is achieved
+ by filling the integer_variables vector with all possible
+ indices.
+ """
+ ivs = []
+
+ for i in range(self.get_column_count()):
+ ivs.append(i+1)
+ if self._lp != None:
+ lpsolve('set_int', self._lp, i+1, 1)
+
+ self.integer_variables = ivs
+
+
+
+ @property
+ def scale_mode(self):
+ """
+ The scaling mode used for handling floating point numbers.
+ See <http://lpsolve.sourceforge.net/5.5/scaling.htm> for more
+ information.
+ """
+ return self._scale_mode
+
+
+ @scale_mode.setter
+ def scale_mode(self, value):
+ self._scale_mode = value
+
+ if self._lp != None:
+ lpsolve('set_scaling', self._lp, value)
+
+
+