Module docplex.cp.solution¶
This module contains the different elements representing the result to a solver request. The main classes are:
CpoRunResult
: root class for all results returned by the solver. It contains general purpose information such as the model that has been solved, solver parameters, solver info and log.CpoSolveResult
: result of a solve request, including a solution to the model if any.CpoRefineConflictResult
: result of a refine conflict request.
These classes are using the following classes to store utility information:
CpoSolverInfos
: miscellaneous information coming from the solver.CpoProcessInfos
: miscellaneous information about the processing and solving of the model by the Python API.
When a solution is found by the solver, it is represented by the following classes:
CpoModelSolution
: aggregation of all individual model element solutions,CpoIntVarSolution
: solution of an integer variable,CpoIntervalVarSolution
: solution of an interval variable,CpoSequenceVarSolution
: solution of a sequence variable,CpoStateFunctionSolution
: solution of a state function, and
These solution objects can be used in multiple ways:
 To represent a complete (fully instantiated) solution, where each model has a unique fixed value, as returned by a successful model solve.
 To represent a partial model solution, that is proposed as a solve starting point (see
docplex.cp.model.CpoModel.set_starting_point()
) In this case, not all variables are present in the solution, and some of them may be partially instantiated. To represent a partial model solution that is returned by the solver as result of calling method
docplex.cp.solver.solver.CpoSolver.propagate()
.
Detailed description¶

class
docplex.cp.solution.
CpoFloatVarSolution
(expr, value)[source]¶ Bases:
docplex.cp.solution.CpoVarSolution
Constructor
Parameters:  expr – Variable expression, object of class
CpoFloatVar
. None if unknown.  value – Variable value, or domain if not completely instantiated
 expr – Variable expression, object of class

class
docplex.cp.solution.
CpoIntVarSolution
(expr, value)[source]¶ Bases:
docplex.cp.solution.CpoVarSolution
This class represents a solution to an integer variable.
 The solution can be:
 complete when the value is a single integer,
 partial when the value is a domain, set of multiple values.
A domain is a list of discrete integer values and/or intervals of values represented by a tuple containing interval min and max values (included).
 For example, following are valid domains for an integer variable:
 7 (complete solution)
 (1, 2, 4, 9)
 (2, 3, (5, 7), 9, (11, 13))
Constructor
Parameters:  expr – Variable expression, object of class
CpoIntVar
. None if unknown.  value – Variable value, or domain if not completely instantiated

domain_contains
(value)[source]¶ Check whether a given value is in the domain of the variable
Parameters: val – Value to check Returns: True if the value is in the domain, False otherwise

class
docplex.cp.solution.
CpoIntervalVarSolution
(expr, presence=None, start=None, end=None, size=None, length=None)[source]¶ Bases:
docplex.cp.solution.CpoVarSolution
This class represents a solution to an interval variable.
The solution can be complete if all attribute values are integers, or partial if at least one of them is an interval expressed as a tuple.
Constructor
Parameters:  expr – Variable expression, object of class
CpoIntervalVar
. None if unknown.  presence – Presence indicator (True for present, False for absent, None for undetermined). Default is None.
 start – Value of start, or tuple representing the start range. Default is None.
 end – Value of end, or tuple representing the end range. Default is None.
 size – Value of size, or tuple representing the size range. Default is None.
 length – Value of the length, or tuple representing the length range. Default is None. Not to be used if other values are integers.

get_end
()[source]¶ Gets the interval end.
To get the bounds of the returned domain, in particular if not fixed, use methods
docplex.cp.expression.get_domain_min()
anddocplex.cp.expression.get_domain_max()
Returns: Interval end value, or domain (tuple (min, max)) if not fully instantiated. None if interval is absent.

get_length
()[source]¶ Gets the length of the interval.
Length of the interval is the difference between end and start.
To get the bounds of the returned domain, in particular if not fixed, use methods
docplex.cp.expression.get_domain_min()
anddocplex.cp.expression.get_domain_max()
Returns: Interval length value, or domain (tuple (min, max)) if not fully instantiated. None if interval is absent.

get_size
()[source]¶ Gets the size of the interval.
The size of the interval is the amount of work done in the interval, that depends on the intensity function that has been associated to the interval.
To get the bounds of the returned domain, in particular if not fixed, use methods
docplex.cp.expression.get_domain_min()
anddocplex.cp.expression.get_domain_max()
Returns: Interval size value, or domain (tuple (min, max)) if not fully instantiated. None if interval is absent.

get_start
()[source]¶ Gets the interval start.
To get the bounds of the returned domain, in particular if not fixed, use methods
docplex.cp.expression.get_domain_min()
anddocplex.cp.expression.get_domain_max()
Returns: Interval start value, or domain (tuple (min, max)) if not fully instantiated. None if interval is absent.

get_value
()[source]¶ Gets the interval variable value as a tuple (start, end, size), or () if absent.
If the variable is absent, then the result is an empty tuple.
If the variable is fully instantiated, the result is a tuple of 3 integers (start, end, size). The variable length, easy to compute as end  start, can also be retrieved by calling
get_length()
.If the variable is partially instantiated, the result is a tuple (start, end, size, length) where each individual value can be an integer or an interval expressed as a tuple.
Returns: Interval variable value as a tuple.

is_absent
()[source]¶ Check if the interval is absent.
Returns: True if interval is absent, False otherwise.
 expr – Variable expression, object of class

class
docplex.cp.solution.
CpoModelSolution
[source]¶ Bases:
object
This class represents a solution to the problem represented by the model. It contains the solutions for the model variables plus the value of the objective(s), if any.
Each variable solution can be accessed using its name, or the variable object of the model. The solution is either
CpoIntVarSolution
,CpoIntervalVarSolution
,CpoSequenceVarSolution
orCpoStateFunctionSolution
depending on the type of the variable.A variable solution can be accessed in two ways:
 using the method
CpoModelSolution.get_var_solution()
, that returns an object representing the solution to the variable, or None if the variable is not in the solution.  using the standard Python expression sol[<var>] that does the same but raises a KeyError exception if the variable is not in the solution.
 Depending if the request to solver was a solve or a propagate, the solution can be:
 complete, if each variable is assigned to a single value,
 partial if not all variables are defined, or if some variables are defined with domains that are not restricted to a single value.
An instance of this class may also be created explicitly by the programmer of the model to express a starting point that can be passed to the model to optimize its solve (see
docplex.cp.model.CpoModel.set_starting_point()
for details).
add_integer_var_solution
(var, value)[source]¶ Add a new integer variable solution.
The solution can be complete if the value is a single integer, or partial if the value is a domain, given as a list of integers or intervals expressed as tuples.
Parameters:  var – Variable expression, object of class
CpoIntVar
.  value – Variable value, or domain if not completely instantiated
 var – Variable expression, object of class

add_interval_var_solution
(var, presence=None, start=None, end=None, size=None, length=None)[source]¶ Add a new interval variable solution.
The solution can be complete if all attribute values are integers, or partial if at least one of them is an interval expressed as a tuple.
Parameters:  var – Variable expression, object of class
CpoIntervalVar
.  presence – Presence indicator (true for present, false for absent, None for undetermined). Default is None.
 start – Value of start, or tuple representing the start range
 end – Value of end, or tuple representing the end range
 size – Value of size, or tuple representing the size range
 length – Value of the length, or tuple representing the length range. Default is None. Not to be used if other values are integers.
 var – Variable expression, object of class

add_kpi_value
(name, value)[source]¶ Add a KPI value to this solution
Parameters:  name – Name of the KPI
 value – Model variable representing this KPI

add_var
(var, value=None, presence=None, start=None, end=None, size=None)[source]¶ Add a solution to a integer or interval variable.
Parameters:  var – CPO variable (object of a class extending
CpoVariable
)  value (Optional) – Value of the variable if the variable is a integer variable. Can be a domain if variable is not completely instantiated.
 presence (Optional) – Presence indicator (true for present, false for absent, None for undetermined), if the variable is an interval variable.
 start (Optional) – Value of start, or tuple representing the start range, if the variable is an interval variable.
 end (Optional) – Value of end, or tuple representing the end range, if the variable is an interval variable.
 size (Optional) – Value of size, or tuple representing the size range, if the variable is an interval variable.
 var – CPO variable (object of a class extending

add_var_solution
(vsol)[source]¶ Add a solution to a variable to this model solution.
Parameters: vsol – Variable solution (object of a class extending CpoVarSolution
)

get_all_var_solutions
()[source]¶ Gets the list of all variable solutions from this model solution.
Returns: List of all variable solutions (class extending CpoVarSolution
).

get_as_constraints
()[source]¶ Build a list of constraints corresponding to this solution.
This method builds a list of constraints that force the model variables to correspond to this solution.
It does not consider the KPIs and objective values, only the decision variables: integer, floating point, interval, sequence variables and state functions.
The result list of constraints can be added to the model using
add()
, for example to callrefine_conflict()
to identify which constraint(s) does not allow this solution to comply to the model constraints.(From an initial version provided by P.Laborie)
Returns: List of constraints corresponding to this solution

get_kpi_value
(name)[source]¶ Get the value of a KPI
Parameters: name – Name of the KPI Returns: Value of the KPI Raises: KeyError if KPI is not in the solution.

get_kpis
()[source]¶ Get the solution KPIs.
Returns: Ordered dictionary containing value of the KPIs that have been defined in the model. Key is KPI publish name, value is expression value. Keys are sorted in the order the KPIs have been defined.

get_objective_bound
()[source]¶ Gets the numeric values of the first objective bound.
Returns: First objective bound values, None if none.

get_objective_bounds
()[source]¶ Gets the numeric values of all objectives bound.
Note that when
minimize_static_lex()
ormaximize_static_lex()
is used, the bound values must be taken as a whole, as are the values delivered byget_objective_values()
. One cannot interpret bound values on each criterion independently. For example, suppose, we have a problem with two criteria specified to minimize_static_lex, a number of workers, and a number of days to complete a job. That is, we always prefer to use less workers, but for equal numbers of workers, we prefer to take less days. Then a solution with 3 workers and 10 days is perfectly compatible with a lower bound of 2 workers and 13 days, even though the lower bound on the number of days is higher than the value in the solution.Returns: Array of all objective bound values, None if none.

get_objective_gap
()[source]¶ Gets the numeric values of the gap between the first objective value and objective bound.
For a single objective, gap is calculated as gap = abs(value  bound) / max(1e10, abs(value))
Returns: First objective gap value, None if none.

get_objective_gaps
()[source]¶ Gets the numeric values of the gap between objective value and objective bound.
For a single objective, gap is calculated as gap = abs(value  bound) / max(1e10, abs(value))
For multiple objectives, each gap is the gap between corresponding value and bound. However, after the first gap whose value is not within optimality tolerance specified by
OptimalityTolerance
andRelativeOptimalityTolerance
, all returned gap values are positive infinity.Returns: Array of all objective gap values, None if none.

get_objective_value
()[source]¶ Gets the numeric values of the first objectives.
If the solution is partial, objective value may be an interval expressed as a tuple (min, max)
Returns: First objective value, None if none.

get_objective_values
()[source]¶ Gets the numeric values of all objectives.
If the solution is partial, each objective value may be an interval expressed as a tuple (min, max)
Returns: Array of objective values, None if none.

get_value
(expr)[source]¶ Gets the value of a variable or a KPI.
This method first find the variable with
get_var_solution()
and, if exists, returns the result of a call to the method get_value() on this variable.The expression can also be the name of a KPI.
The result depends on the type of the variable. For details, please consult documentation of methods:
Note that the builtin method __getitem__() is overwritten to call this method. Writing sol.get_value(x) is then equivalent to write sol[x].
Parameters: expr – Variable expression, variable name or KPI name. Returns: Variable value, None if variable is not found. Raises: KeyError if expression is not in the solution.

get_var_solution
(expr)[source]¶ Gets a variable solution from this model solution.
Parameters: expr – Variable expression or variable name if any Returns: Variable solution (class extending CpoVarSolution
), None if variable is not found

has_var_solutions
()[source]¶ Check if this solution contains variable solutions.
Returns: True if there is at least one variable solution.

is_empty
()[source]¶ Check whether this solution contains any information
Returns: True if this solution contains no data

map_solution
(sobj)[source]¶ Map a python object on this solution.
This method builds a copy of the source object and replace in its attributes all occurrences of model expressions by their value in this solution. This method is called recursively on all child objects.
Parameters: sobj – Source object Returns: Copy of the source object where model expressions are replaced by their values

print_solution
(out=None)[source]¶ Prints the solution on a given output.
If the given output is a string, it is considered as a file name that is opened by this method using ‘utf8’ encoding.
DEPRECATED. Use
write()
instead.Parameters: out – Target output stream or output file, standard output if not given.

set_value
(var, value)[source]¶ Set the value of a variable.
This method allows to set an integer variable or an interval variable with the short representation used to represent it, as returned by
CpoIntVarSolution.get_value()
orCpoIntervalVarSolution.get_value()
.For an integer variable, value can be:
 If the variable is fully instantiated, a single integer.
 If the variable is partially instantiated, a domain expressed as a list of integers or intervals.
For an interval variable, value can be:
 If the variable is absent, an empty tuple.
 If the variable is fully instantiated, a tuple of 3 integers (start, end, size).
 If the variable is partially instantiated, a tuple (start, end, size, length) where each individual value can be an integer or an interval expressed as a tuple.
Note that the builtin method __setitem__() is overwritten to call this method. Writing sol.set_value(x, y) is then equivalent to write sol[x] = y.
New in version 2.9.
Parameters:  var – Model variable
 value – short representation of the variable value
 using the method

class
docplex.cp.solution.
CpoProcessInfos
[source]¶ Bases:
docplex.cp.utils.InfoDict
Dictionary of various process information.
This class groups various information related to the processing of the model by the Python API. It is implemented as an extension of the class
InfoDict
and takes profit of the methods such aswrite()
that allows to easily print the full content of the information structure.Note that the content is purely informative. Information names and values depends on the implementation of the solver agent that has been used to solve the model.
This class provides few methods to access the most important information stored in it. All information is available using regular dictionary access expression.

get_model_build_time
()[source]¶ Get the time spent to build the model.
Modeling time is computed as the time spent between model creation and last addition of a model expression.
Returns: Total modeling time in seconds.


class
docplex.cp.solution.
CpoRefineConflictResult
(model)[source]¶ Bases:
docplex.cp.solution.CpoRunResult
This class represents the result of a call to the conflict refiner.
A conflict is a subset of the constraints and/or variables of the model which are mutually contradictory.
The conflict refiner first examines the full infeasible model to identify portions of the conflict that it can remove. By this process of refinement, the conflict refiner arrives at a minimal conflict. A minimal conflict is usually smaller than the full infeasible model and thus makes infeasibility analysis easier. Since the conflict is minimal, removal of any one of these constraints will remove that particular cause for infeasibility. There may be other conflicts in the model; consequently, repair of a given conflict does not guarantee feasibility of the remaining model. If a model happens to include multiple independent causes of infeasibility, then it may be necessary for the user to repair one such cause and then repeat the diagnosis with further conflict analysis.

get_all_member_constraints
()[source]¶ Returns the list of all constraints that are certainly member of the conflict.
Same as
get_member_constraints()
.Returns: List of model constraints (class CpoExpr) certainly member of the conflict.

get_all_member_variables
()[source]¶ Returns the list of all variables that are certainly member of the conflict.
Same as
get_member_variables()
.Returns: List of model variables (class CpoIntVar or CpoIntervalVar) certainly member of the conflict.

get_all_possible_constraints
()[source]¶ Returns the list of all constraints that are possibly member of the conflict.
Same as
get_possible_constraints()
.Returns: List of model constraints (class CpoExpr) possibly member of the conflict.

get_all_possible_variables
()[source]¶ Returns the list of all variables that are possibly member of the conflict.
Same as
get_possible_variables()
.Returns: List of model variables (class CpoIntVar or CpoIntervalVar) possibly member of the conflict.

get_conflict_status
()[source]¶ Returns the status of the conflict refiner.
Returns: Conflict refiner status, with value in CONFLICT_STATUS_*

get_cpo
()[source]¶ Returns the conflict represented in CPO format.
Returns: String containing the conflict in CPO format, None if not given.

get_member_constraints
()[source]¶ Returns the list of all constraints that are certainly member of the conflict.
Returns: List of model constraints (class CpoExpr) certainly member of the conflict.

get_member_variables
()[source]¶ Returns the list of all variables that are certainly member of the conflict.
Returns: List of model variables (class CpoIntVar or CpoIntervalVar) certainly member of the conflict.

get_possible_constraints
()[source]¶ Returns the list of all constraints that are possibly member of the conflict.
Returns: List of model constraints (class CpoExpr) possibly member of the conflict.

get_possible_variables
()[source]¶ Returns the list of all variables that are possibly member of the conflict.
Returns: List of model variables (class CpoIntVar or CpoIntervalVar) possibly member of the conflict.

is_conflict
()[source]¶ Checks if this descriptor contains a valid conflict.
Returns: True if there is a conflict, False otherwise.

print_conflict
(out=None)[source]¶ Prints this conflict on a given output.
If the given output is a string, it is considered as a file name that is opened by this method using ‘utf8’ encoding.
DEPRECATED. Use
write()
instead.Parameters: out – Target output stream or output file, standard output if not given.

write
(out=None, add_cpo=True)[source]¶ Write the conflict
If the given output is a string, it is considered as a file name that is opened by this method using ‘utf8’ encoding.
Parameters:  out (Optional) – Target output stream or file name. If not given, default value is sys.stdout.
 add_cpo (Optional) – Add the conflict in CPO file format after the detailed list of conflict elements. By default, this parameter is set to true.


class
docplex.cp.solution.
CpoRunResult
(model)[source]¶ Bases:
object
This class is an abstract class extended by classes representing the result of a call to the solver.
 It contains the following elements:
 model that has been solved,
 solver parameters,
 solver information,
 solver output log, if configuration has been set to store it (default),
 internal processing information.

get_info
(name, default=None)[source]¶ Gets a particular solver information attribute.
Deprecated. use
get_solver_info()
instead.Parameters:  name – Name of the information to get
 default – (optional) Default value if not found. None by default.
Returns: Information attribute value, None if not found.

get_infos
()[source]¶ Gets the complete dictionary of solver information attributes.
Deprecated. use
get_solver_infos()
instead.Returns: Solver information, object of class CpoSolverInfos
.

get_parameter
(name, default=None)[source]¶ Get a particular solving parameter.
Parameters:  name – Name of the parameter to get
 default – (optional) Default value if not found. None by default.
Returns: Parameter value, default value if not found.

get_parameters
()[source]¶ Gets the complete dictionary of solving parameters.
Returns: Solving parameters, object of class CpoParameters
.

get_process_info
(name, default=None)[source]¶ Get a particular process information.
Parameters:  name – Name of the process info to get
 default – (optional) Default value if not found. None by default.
Returns: Value of the process info, default value if not found.

get_process_infos
()[source]¶ Gets the set of informations provided by the Python API concerning the solving of the model.
Returns: Object of class CpoProcessInfos
that contains general information on model processing.

get_solver_info
(name, default=None)[source]¶ Gets a particular solver information attribute.
Parameters:  name – Name of the information to get
 default – (optional) Default value if not found. None by default.
Returns: Information attribute value, None if not found.

get_solver_infos
()[source]¶ Gets the set of information provided by the solver concerning to the solving of the model.
Returns: Solver information, object of class CpoSolverInfos
.

class
docplex.cp.solution.
CpoSequenceVarSolution
(expr, lvars)[source]¶ Bases:
docplex.cp.solution.CpoVarSolution
This class represents a solution to a sequence variable.
Constructor
Parameters:  expr – Variable expression, object of class
CpoSequenceVar
. None if unknown.  lvars – Ordered list of interval variable solutions that are in this sequence
(objects of class
CpoIntervalVarSolution
), or list of interval variables (object of classCpoIntervalVar
).
 expr – Variable expression, object of class

class
docplex.cp.solution.
CpoSolveResult
(model)[source]¶ Bases:
docplex.cp.solution.CpoRunResult
This class represents the result of a returned by a call to a model solve request.
 On top of those already stored in
CpoRunResult
, it contains the following elements:  solve status(es),
 solution, if any, object of class
CpoModelSolution
.
If this result contains a solution, the methods implemented in the class
CpoModelSolution
to access solution elements are available directly from this class.Constructor
Parameters: model – Related model 
get_all_var_solutions
()[source]¶ Gets the list of all variable solutions from this model solution.
Returns: List of all variable solutions (class CpoVarSolution
).

get_fail_status
()[source]¶ Gets the solving fail status.
This method is deprecated since release 12.8. Use
get_search_status()
andget_stop_cause()
instead.Returns: Fail status, element of the global list ALL_FAIL_STATUSES
.

get_kpis
()[source]¶ Get the solution kpis
Returns: Dictionary containing value of the KPIs that have been defined in the model, None if none.

get_objective_bound
()[source]¶ Gets the numeric values of the first objective bound.
Returns: First objective bound values, None if none.

get_objective_bounds
()[source]¶ Gets the numeric values of all objectives bound.
Note that when
minimize_static_lex()
ormaximize_static_lex()
is used, the bound values must be taken as a whole, as are the values delivered byget_objective_values()
. One cannot interpret bound values on each criterion independently. For example, suppose, we have a problem with two criteria specified to minimize_static_lex, a number of workers, and a number of days to complete a job. That is, we always prefer to use less workers, but for equal numbers of workers, we prefer to take less days. Then a solution with 3 workers and 10 days is perfectly compatible with a lower bound of 2 workers and 13 days, even though the lower bound on the number of days is higher than the value in the solution.Returns: Array of all objective bound values, None if none.

get_objective_gap
()[source]¶ Gets the numeric values of the gap between the first objective value and objective bound.
For a single objective, gap is calculated as gap = value  bound / max(1e10, value)
Returns: First objective gap value, None if not defined.

get_objective_gaps
()[source]¶ Gets the numeric values of the gap between objective value and objective bound.
For a single objective, gap is calculated as gap = value  bound / max(1e10, value)
For multiple objectives, each gap is the gap between corresponding value and bound. However, after the first gap whose value is not within optimality tolerance specified by
OptimalityTolerance
andRelativeOptimalityTolerance
, all returned gap values are positive infinity.Returns: Array of all objective gap values, None if not defined.

get_objective_value
()[source]¶ Gets the numeric values of the first objective.
Returns: First objective value, None if none.

get_objective_values
()[source]¶ Gets the numeric values of all objectives.
Returns: Array of all objective values, None if none.

get_search_status
()[source]¶ Gets the search status.
This solver information is provided by the COS 12.8 CP solver in addition/replacement to solve_status. Value is None if the solver is earlier than this version.
Returns: Search status, element of the global list ALL_SEARCH_STATUSES
. None if not defined.

get_solution
()[source]¶ Get the model solution
Returns: Model solution, object of class CpoModelSolution
, None if no solution.

get_solve_status
()[source]¶ Gets the solve status.
Returns: Solve status, element of the global list ALL_SOLVE_STATUSES
.

get_solve_time
()[source]¶ Gets the solve time required for this solution.
Returns: (float) Solve time in seconds.

get_stop_cause
()[source]¶ Gets the stop cause.
This solver information is provided by the COS 12.8 CP solver in addition/replacement to fail_status. Value is None if the solver is earlier than this version.
Returns: Stop cause, element of the global list ALL_STOP_CAUSES
. None if not defined.

get_value
(name)[source]¶ Gets the value of a variable.
For IntVar, value is an integer. For IntervalVar, value is a tuple (start, end, size), () if absent. For SequenceVar, value is list of interval variable solutions. For StateFunction, value is list of steps.
Parameters: name – Variable name, or model variable descriptor. Returns: Variable value, None if variable is not found.

get_var_solution
(name)[source]¶ Gets a variable solution from this model solution.
Parameters: name – Variable name or variable expression. Returns: Variable solution, object of class CpoVarSolution
, None if not found.

is_new_solution
()[source]¶ Checks if this result contains a new valid solution to the problem.
A new solution is present if the solve status is ‘Feasible’ or ‘Optimal’. Optimality of the solution should be tested using method
is_solution_optimal()
.Note that, if the solve is done by calling multiple times
docplex.cp.solver.solver.CpoSolver.search_next()
, this method may return False if the solve status is ‘Optimal’. This is because the same solution has already been returned with status ‘Feasible’.Returns: True if this result contains a new solution to the problem.

is_solution
()[source]¶ Checks if this result contains a solution to the problem.
A solution is present if the solve status is ‘Feasible’ or ‘Optimal’. Optimality of the solution should be tested using method
is_solution_optimal()
.This method returns True if a valid solution is present, even if it has already been provided in a previous result. Use
is_new_solution()
to be sure the solution is a new one.Returns: True if this result contains a solution to the problem.

is_solution_optimal
()[source]¶ Checks if this descriptor contains an optimal solution to the problem.
Returns: True if there is a solution that is optimal.

map_solution
(sobj)[source]¶ Map a python object on the solution of this result.
This method builds a copy of the source object and replace in its attributes all occurrences of model expressions by their value in this solution. This method is called recursively on all child objects.
Parameters: sobj – Source object Returns: Copy of the source object where model expressions are replaced by their values

print_solution
(out=None)[source]¶ Prints the solution on a given output.
If the given output is a string, it is considered as a file name that is opened by this method using ‘utf8’ encoding.
DEPRECATED. Use write() instead.
Parameters: out – Target output stream or output file, standard output if not given.
 On top of those already stored in

class
docplex.cp.solution.
CpoSolverInfos
[source]¶ Bases:
docplex.cp.utils.InfoDict
Dictionary of various solver informations.
This class groups various information returned by the solver at the end of the solve. It is implemented as an extension of the class
docplex.cp.utils.InfoDict
and takes profit of the methods such aswrite()
that allows to easily print the full content of the information structure.The keys of this disctioanr are those defined by the CP solver itsefs. This class implements accessors for the most important of them.

get_number_of_constraints
()[source]¶ Gets the number of constraints in the model.
Returns: Number of constraints.

get_number_of_integer_vars
()[source]¶ Gets the number of integer variables in the model.
Returns: Number of integer variables.

get_number_of_interval_vars
()[source]¶ Gets the number of interval variables in the model.
Returns: Number of interval variables.

get_number_of_sequence_vars
()[source]¶ Gets the number of sequence variables in the model.
Returns: Number of sequence variables.


class
docplex.cp.solution.
CpoStateFunctionSolution
(expr, steps)[source]¶ Bases:
docplex.cp.solution.CpoVarSolution
This class represents a solution to a step function.
A solution to a step function is represented by a list of steps. A step is a triplet (start, end, value) that gives the value of the function on the interval [start, end).
Constructor
Parameters:  expr – Variable expression, object of class
CpoStateFunction
. None in unknown.  steps – List of function steps represented as tuples (start, end, value).
 expr – Variable expression, object of class

class
docplex.cp.solution.
CpoVarSolution
(expr)[source]¶ Bases:
object
This class is the super class of all classes representing a solution to a variable.
Constructor
Parameters: expr – Variable expression, object of class CpoVariable
or extending class.
get_expr
()[source]¶ Get the variable expression for which this object is a solution.
Returns: Model variable expression.
