Retrieving solution status and values¶
Status of the solution¶
A feasible solution is an assignment of values to decisions variables such that:
all constraints are satisfied
no objective has undefined value. Undefined values can occur when performing illegal mathematical operations (square root of negative number for instance) or accessing outside the bounds of an array.
Note that some values can be undefined in a feasible solution, provided that all
objectives have valid values. For instance a conditional expression
x > 0 ? sqrt(x) : sqrt(-x)
always has one of its branches undefined, but its
output is always valid.
At the end of the search, the status of the solution can be one of the following:
INCONSISTENT
if the solver was able to prove that no feasible solution can be foundINFEASIBLE
if no feasible solution has been found yetFEASIBLE
if a feasible solution has been computedOPTIMAL
if a feasible solution has been found whose optimality has been proven (objective value within 0.01% of computed bound for each objective).
This status can be retrieved at any time after the model has been closed.
// it allows you to access to the current solution, for instance in the output() function
function output() {
println("Status is " + hxSolution.status);
// you can also compare the status to its possible values
if (hxSolution.status == "INCONSISTENT") ...
else if (hxSolution.status == "INFEASIBLE") ...
else if (hxSolution.status == "FEASIBLE") ...
else if (hxSolution.status == "OPTIMAL") ...
}
# with optimizer an object of type HexalyOptimizer
print("Status is " + optimizer.solution.status)
# you can also compare the status to its possible values
if optimizer.solution.status == HxSolutionStatus.INCONSISTENT:
...
elif optimizer.solution.status == HxSolutionStatus.INFEASIBLE:
...
elif optimizer.solution.status == HxSolutionStatus.FEASIBLE:
...
elif optimizer.solution.status == HxSolutionStatus.OPTIMAL:
...
// with optimizer an object of type HexalyOptimizer
std::cout << "Status is " << optimizer.getSolution().getStatus() << std::endl;
// you can also compare the status to its possible values
if (optimizer.getSolution().getStatus() == SS_INCONSISTENT) ...
else if (optimizer.getSolution().getStatus() == SS_INFEASIBLE) ...
else if (optimizer.getSolution().getStatus() == SS_FEASIBLE) ...
else if (optimizer.getSolution().getStatus() == SS_OPTIMAL) ...
// with optimizer an object of type HexalyOptimizer
Console.Writeline("Status is " + optimizer.GetSolution().GetStatus());
// you can also compare the status to its possible values
if (optimizer.GetSolution().GetStatus() == HxSolutionStatus.Inconsistent) ...
else if (optimizer.GetSolution().GetStatus() == HxSolutionStatus.Infeasible) ...
else if (optimizer.GetSolution().GetStatus() == HxSolutionStatus.Feasible) ...
else if (optimizer.GetSolution().GetStatus() == HxSolutionStatus.Optimal) ...
// with optimizer an object of type HexalyOptimizer
System.out.println("Status is " + optimizer.getSolution().getStatus());
// you can also compare the status to its possible values
if (optimizer.getSolution().getStatus() == HxSolutionStatus.Inconsistent) ...
else if (optimizer.getSolution().getStatus() == HxSolutionStatus.Infeasible) ...
else if (optimizer.getSolution().getStatus() == HxSolutionStatus.Feasible) ...
else if (optimizer.getSolution().getStatus() == HxSolutionStatus.Optimal) ...
Values of numeric variables and expressions¶
Numeric variables and expressions are expressions of the mathematical model
whose value is a boolean and integer of a floating point number. Three methods
are available on expressions to identify these expressions: isBool()
,
isInt()
and isDouble()
(or in Python is_bool
, is_int
and
is_double
and in C# IsBool()
, IsInt()
and IsDouble()
).
As mentioned above, an expression can have an undefined value, what can be
detected with function is_undefined
(Python), isUndefined
(Hexaly Modeler/Java/C++) or IsUndefined
(C#).
function output() {
// with x an HxExpression
if (x.isUndefined()) throw "X was expected to have a valid value";
println("x is boolean" ? + (x.isBool() ? "YES": "NO"));
println("value of x is "+ x.value);
}
# with x an object of type HxExpression
if x.is_undefined():
raise Exception("X was expected to have a valid value")
print("x is boolean ? " + ("YES" if x.is_bool() else "NO"))
print("value of x is " + x.value)
// with x an object of type HxExpression
if (x.isUndefined()) throw "X was expected to have a valid value";
std::cout << "x is boolean ? "<< (x.isBool() ? "YES" : "NO") << std::endl;
// same method to retrieve int and bool values
std::cout << "value of x is "<< (x.isDouble() ? x.getDoubleValue() : x.getIntValue() << std::endl;
// with x an object of type HxExpression
if (x.IsUndefined()) throw new Exception("X was expected to have a valid value");
Console.Writeline("x is boolean ? " + (x.isBool() ? "YES": "NO"));
// same method to retrieve int and bool values
Console.Writeline("value of x is " + (x.IsDouble() ? x.GetDoubleValue() : x.GetIntValue());
// with x an object of type HxExpression
if (x.isUndefined()) throw new Exception("X was expected to have a valid value");
System.out.println("x is boolean ? " + (x.isBool() ? "YES": "NO"));
// same method to retrieve int and bool values
System.out.println("value of x is " + (x.isDouble() ? x.getDoubleValue() : x.getIntValue());
Values of collection and array variables and expressions¶
Some expressions of a Hexaly Optimizer model do not take numeric values. For instance the value of a set or a list is a collection of integers. Similarly the value of an array expression is an array of values.
Before retrieving the value of the expression, the user can check its type using the necessary methods available on HxExpression objects. The values of these expressions are of type HxCollection (for set and list) or HxArray (for arrays).
These types can be printed directly (the output is formatted with brackets e.g. [4, 8, 7, 2]) or the user can retrieve its values one by one.
function output() {
// with mycoll a set or list expression
local coll = mycoll.value;
println("Collection values = " + coll);
println("Collection size = " + coll.count());
// note that indexing starts at 0 and that the values of a set
// are given in increasing order
println("Collection 8th value = " + coll[7]);
// with myarray an array expression
local arrayvals = myarray.value;
println("Array value = " + arrayvals);
println("Array size = " + arrayvals.count());
println("Array 8th value = " + arrayvals[7]));
}
# with mycoll a set or list expression
coll = mycoll.value
print("Collection values = " + coll)
print("Collection size = " + coll.count())
# note that indexing starts at 0 and that the values of a set
# are given in increasing order
print("Collection 8th value = " + coll[7])
# with myarray an array expression
arrayvals = myarray.value
print("Array value = " + arrayvals)
print("Array size = " + arrayvals.count())
print("Array 8th value is double = " + arrayvals.is_double(7))
print("Array 8th value = " + arrayvals[7])
// with mycoll a set or list expression
HxCollection coll = mycoll.getCollectionValue();
std::cout << "Collection values = " << coll.toString() << std::endl;
std::cout << "Collection size = " << coll.count() << std::endl;
// note that indexing starts at 0 and that the values of a set
// are given in increasing order
std::cout << "Collection 8th value = " << coll[7] << std::endl;
// with myarray an array expression
HxArray arrayvals = myarray.getArrayValue();
std::cout << "Array value = " << arrayvals.toString() << std::endl;
std::cout << "Array size = " << arrayvals.count() << std::endl;
std::cout << "Array 8th value is double = " << arrayvals.isDouble(7) << std::endl;
std::cout << "Array 8th value = " << arrayvals[7] << std::endl;
// with mycoll a set or list expression
HxCollection coll = mycoll.GetCollectionValue();
Console.Writeline("Collection values = " + coll);
Console.Writeline("Collection size = " + coll.Count());
// note that indexing starts at 0 and that the values of a set
// are given in increasing order
Console.Writeline("Collection 8th value = " + coll[7]);
// with myarray an array expression
HxArray arrayvals = myarray.GetArrayValue();
Console.Writeline("Array value = " + arrayvals);
Console.Writeline("Array size = " + arrayvals.Count());
Console.Writeline("Array 8th value is double = " + arrayvals.IsDouble(7));
Console.Writeline("Array 8th value = " + arrayvals[7]);
// with mycoll a set or list expression
HxCollection coll = mycoll.getCollectionValue();
System.out.println("Collection values = " + coll);
System.out.println("Collection size = " + coll.count());
// note that indexing starts at 0 and that the values of a set
// are given in increasing order
System.out.println("Collection 8th value = " + coll.get(7));
HxArray arrayvals = arr.getArrayValue();
System.out.println("Array value = " + arrayvals);
System.out.println("Array size = " + arrayvals.count());
System.out.println("Array 8th value is double = " + arrayvals.isDouble(7));
System.out.println("Array 8th value = " + arrayvals.getDoubleValue(7));
Values of interval variables and expressions¶
The value of an interval decision variable or a range expression is an interval characterized by a start value, an end value, and a size.
Before retrieving the value of the expression, the user can check its type using the necessary methods available on HxExpression objects. The values of these expressions are of type HxInterval.
These types can be printed directly (the output is formatted with points e.g. 5…10) or the user can retrieve its charateristics (start, end, size) one by one.
function output() {
// with myinterval an interval or range expression
local inter = myinterval.value;
println("Interval = " + inter);
println("Interval size = " + inter.count());
println("Interval start = " + inter.start);
println("Interval end = " + inter.end);
}
# with myinterval an interval or range expression
inter = myinterval.value
print("Interval value = " + inter)
print("Interval size = " + inter.count())
print("Interval start = " + inter.start())
print("Interval end = " + inter.end())
// with myinterval an interval or range expression
HxInterval inter = myinterval.getIntervalValue();
std::cout << "Interval value = " << inter.toString() << std::endl;
std::cout << "Interval size = " << inter.count() << std::endl;
std::cout << "Interval start = " << inter.start() << std::endl;
std::cout << "Interval end = " << inter.end() << std::endl;
// with myinterval an interval or range expression
HxInterval inter = myinterval.GetIntervalValue();
Console.Writeline("Interval value = " + inter);
Console.Writeline("Interval size = " + inter.Count());
Console.Writeline("Interval start = " + inter.Start());
Console.Writeline("Interval end = " + inter.End());
// with myinterval an interval or range expression
HxInterval inter = myinterval.getIntervalValue();
System.out.println("Interval value = " + inter);
System.out.println("Interval size = " + inter.count());
System.out.println("Interval start = " + inter.start());
System.out.println("Interval end = " + inter.end());