def irow(self, i): """ Evaluate sparse gradient of the linear part of the i-th constraint. Useful to obtain constraint rows when problem is a linear programming problem. """ try: sri_dict = _amplpy.eval_row(i) except: raise RunTimeError, "Failed to fetch sparse row" return None sri = sv.SparseVector(self.n, sri_dict) return sri
def irow(self, i): """ Evaluate sparse gradient of the linear part of the i-th constraint. Useful to obtain constraint rows when problem is a linear programming problem. """ try: sri_dict = self.model.eval_row(i) except: raise RuntimeError, "Failed to fetch sparse row" return None sri = sv.SparseVector(self.n, sri_dict) if self.scale_con is not None: sri *= self.scale_con[i] return sri
def sigrad(self, i, x): """ Evaluate sparse gradient of i-th constraint at x. Returns a sparse vector representing the sparse gradient in coordinate format. """ try: sci_dict = _amplpy.eval_sgi(i, x) except: raise RunTimeError, "Failed to fetch sparse constraint gradient" return None self.Jeval += 1 sci = sv.SparseVector(self.n, sci_dict) return sci
def sigrad(self, i, x): """ Evaluate sparse gradient of i-th constraint at x. Returns a sparse vector representing the sparse gradient in coordinate format. """ try: sci_dict = self.model.eval_sgi(i, x) except: raise RuntimeError, "Failed to fetch sparse constraint gradient" return None self.Jeval += 1 sci = sv.SparseVector(self.n, sci_dict) if self.scale_con is not None: sci *= self.scale_con[i] return sci
def cost(self): """ Evaluate sparse cost vector. Useful when problem is a linear program. Return a sparse vector. This method changes the sign of the cost vector if the problem is a maximization problem. """ try: sc_dict = _amplpy.eval_cost() except: raise RunTimeError, "Failed to fetch sparse cost vector" return None sc = sv.SparseVector(self.n, sc_dict) if not self.minimize: sc *= -1 return sc
def sgrad(self, x): """ Evaluate sparse objective gradient at x. Returns a sparse vector. This method changes the sign of the objective gradient if the problem is a maximization problem. """ try: sg_dict = _amplpy.eval_sgrad(x) except: raise RunTimeError, "Failed to fetch sparse gradient of objective" return None self.geval += 1 sg = sv.SparseVector(self.n, sg_dict) if not self.minimize: sg *= -1 return sg