sasoptpy.Model.set_objective

Model.set_objective(self, expression, name, sense=None)[source]

Specifies the objective function for the model

Parameters
expressionExpression

The objective function as an Expression

namestring

Name of the objective value

sensestring, optional

Objective value direction, sasoptpy.MIN or sasoptpy.MAX

Returns
objectiveExpression

Objective function as an Expression object

Notes

  • Default objective sense is minimization MIN.

  • This method replaces the existing objective of the model. When working with multiple objectives, use the Model.append_objective() method.

Examples

>>> profit = so.Expression(5 * sales - 2 * material, name='profit')
>>> m.set_objective(profit, so.MAX)
>>> print(m.get_objective())
 -  2.0 * material  +  5.0 * sales
>>> m.set_objective(4 * x - 5 * y, name='obj')
>>> print(repr(m.get_objective()))
sasoptpy.Expression(exp =  4.0 * x  -  5.0 * y , name='obj')
>>> f1 = m.set_objective(2 * x + y, sense=so.MIN, name='f1')
>>> f2 = m.append_objective( (x - y) ** 2, sense=so.MIN, name='f2')
>>> print(m.to_optmodel(options={'with': 'blackbox', 'obj': (f1, f2)}))
proc optmodel;
var x;
var y;
min f1 = 2 * x + y;
min f2 = (x - y) ^ (2);
solve with blackbox obj (f1 f2);
print _var_.name _var_.lb _var_.ub _var_ _var_.rc;
print _con_.name _con_.body _con_.dual;
quit;