Follow us on Twitter and LinkedIn to get the latest updates from the dev team!
The ObjectiveInstance object stores the information regarding a specific instance of an objective. The instances can be accessed through the function Objective.get of the parent entity.
Objective.get
v = value()
v = value() Get the current value of the objective instance
v
The current value of the objective instance
Create an indexed objective z, get an instance and display its value. Then solve the problem and display the value again.
ampl.eval('var x{i in 1..2} <= i;'); ampl.eval('maximize z{i in 1..2}: x[i];'); z = ampl.getObjective('z'); instance = z.get(1); instance.value ampl.solve; instance.value
gives:
ans = 0 ans = 1
v = astatus
astatus Return the AMPL status for this objective instance.
astatus
The AMPL status for this objective instance.
Create an indexed objective z, get an instance and display its status. Then solve the problem and display it again.
ampl.eval('var x{i in 1..2} <= i;'); ampl.eval('maximize z{i in 1..2}: x[i];'); z = ampl.getObjective('z'); instance = z.get(1); instance.astatus ampl.solve; instance.astatus
ans = in ans = in
v = exitcode
exitcode Get exit code returned by solver after most recent solve with this objective.
exitcode
The exit code returned by solver after most recent solve with this objective.
Create an indexed objective z, get an instance and display its exitcode. Then solve the problem and display it again.
ampl.eval('var x{i in 1..2} <= i;'); ampl.eval('maximize z{i in 1..2}: x[i];'); z = ampl.getObjective('z'); instance = z.get(1); instance.exitcode ampl.solve; instance.exitcode
ans = 0 ans = 0
v = message
message Get the result message returned by solver after most recent solve with this objective.
message
The result message returned by solver after most recent solve with this objective
Create an indexed objective z, get an instance and display the solver message. Then solve the problem and display it again.
ampl.eval('var x{i in 1..2} <= i;'); ampl.eval('maximize z{i in 1..2}: x[i];'); z = ampl.getObjective('z'); instance = z.get(1); instance.message ampl.solve; instance.message
ans = ? ans = CBC 2.8.2 optimal, objective -1 0 iterations
v = result
result Get the result string returned by solver after most recent solve with this objective.
result
The result string returned by solver after most recent solve with this objective.
Create an indexed objective z, get an instance and display its result string. Then solve the problem and display it again.
ampl.eval('var x{i in 1..2} <= i;'); ampl.eval('maximize z{i in 1..2}: x[i];'); z = ampl.getObjective('z'); instance = z.get(1); instance.result ampl.solve; instance.result
ans = ? ans = solved
previous
Objective
next
Parameter