|
PPL Prolog Language Interface 2.0
|
The Prolog interface provides access to the numerical abstractions (convex polyhedra, BD shapes, octagonal shapes, etc.) implemented by the PPL library. A general introduction to the numerical abstractions, their representation in the PPL and the operations provided by the PPL is given in the main PPL user manual. Here we just describe those aspects that are specific to the Prolog interface.
First, here is a list of notes with general information and advice on the use of the interface.
ppl_initialize/0 and ppl_finalize/0. Thus the only interface predicates callable after ppl_finalize/0 are ppl_finalize/0 itself (this further call has no effect) and ppl_initialize/0, after which the interface's services are usable again. Some Prolog systems allow the specification of initialization and deinitialization functions in their foreign language interfaces. The corresponding incarnations of the Prolog interface have been written so that ppl_initialize/0 and/or ppl_finalize/0 are called automatically. Section System-Dependent Features will detail in which cases initialization and finalization is automatically performed or is left to the Prolog programmer's responsibility. However, for portable applications, it is best to invoke ppl_initialize/0 and ppl_finalize/0 explicitly: since they can be called multiple times without problems, this will result in enhanced portability at a cost that is, by all means, negligible.ppl_delete_Polyhedron/1. To understand why this is important, consider a Prolog program and a variable that is bound to a Herbrand term. When the variable dies (goes out of scope) or is uninstantiated (on backtracking), the term it is bound to is amenable to garbage collection. But this only applies for the standard domain of the language: Herbrand terms. In Prolog+PPL, when, for example, a variable bound to a handle for a Polyhedron dies or is uninstantiated, the handle can be garbage-collected, but the polyhedron to which the handle refers will not be released. Once a handle has been used as an argument in ppl_delete_Polyhedron/1, it becomes invalid.k, the identifiers used for the PPL variables must lie between 0 and 
The PPL predicates provided by the Prolog interface are specified below. The specification uses the following grammar rules:
Below is a short description of many of the interface predicates. For full definitions of terminology used here, see the main PPL user manual.
First we describe the domain independent predicates that are included with all instantiations of the Prolog interfaces.
ppl_version_major(?C_int)
Unifies C_int with the major number of the PPL version.
ppl_version_minor(?C_int)
Unifies C_int with the minor number of the PPL version.
ppl_version_revision(?C_int)
Unifies C_int with the revision number of the PPL version.
ppl_version_beta(?C_int)
Unifies C_int with the beta number of the PPL version.
ppl_version(?Atom)
Unifies Atom with the PPL version.
ppl_banner(?Atom)
Unifies Atom with information about the PPL version, the licensing, the lack of any warranty whatsoever, the C++ compiler used to build the library, where to report bugs and where to look for further information.
ppl_Coefficient_bits(?Bits)
Unifies Bits with the number of bits used to encode a Coefficient in the C++ interface; 0 if unbounded.
ppl_Coefficient_is_bounded
Succeeds if and only if the Coefficients in the C++ interface are bounded.
ppl_Coefficient_max(Max)
If the Coefficients in the C++ interface are bounded, then the maximum coefficient the C++ interface can handle is unified with Max. If the Prolog system cannot handle this coefficient, then an exception is thrown. It fails if the Coefficients in the C++ interface are unbounded.
ppl_Coefficient_min(Min)
If the Coefficients in the C++ interface are bounded, then the minimum coefficient the C++ interface can handle is unified with Min. If the Prolog system cannot handle this coefficient, then an exception is thrown. It fails if the Coefficients in the C++ interface are unbounded.
ppl_max_space_dimension(?Dimension_Type)
Unifies Dimension_Type with the maximum space dimension this library can handle.
ppl_initialize
Initializes the PPL interface. Multiple calls to ppl_initialize does no harm.
ppl_finalize
Finalizes the PPL interface. Once this is executed, the next call to an interface predicate must either be to ppl_initialize or to ppl_finalize. Multiple calls to ppl_finalize do no harm. Finalization also releases all remaining numerical domains, MIP problems, powerset iterator objects and PIP problems and invalidates their handles and borrowed views; subsequent initialization does not revive them.
ppl_set_timeout_exception_atom(+Atom)
Sets the atom to be thrown by timeout exceptions to Atom. The default value is time_out.
ppl_timeout_exception_atom(?Atom)
The atom to be thrown by timeout exceptions is unified with Atom.
ppl_set_timeout(+Csecs)
Computations taking exponential time will be interrupted some time after Csecs centiseconds after that call. If the computation is interrupted that way, the current timeout exception atom will be thrown. Csecs must be strictly greater than zero and must not exceed either UINT_MAX or LONG_MAX, the limits of the underlying C++ unsigned and long types. When watchdog timers are supported, an invalid-argument exception is thrown if this range is exceeded. If watchdog timers are unavailable, a logic-error exception is thrown when attempting to set a timeout within the unsigned range. Setting a timeout cancels any previously set timeout, including when the replacement fails.
ppl_reset_timeout
Resets the timeout time so that the computation is not interrupted.
ppl_set_deterministic_timeout(+Unscaled_Weight, +Scale)
Computations taking exponential time will be interrupted some time after reaching the complexity threshold 
Unscaled_Weight must be strictly greater than zero; Scale must be non-negative; an exception is thrown if the computed weight threshold exceeds the maximum allowed value.
NOTE: This "timeout" checking functionality is said to be deterministic because it is not based on actual elapsed time. Its behavior will only depend on (some of the) computations performed in the PPL library and it will be otherwise independent from the computation environment (CPU, operating system, compiler, etc.). The weight mechanism is under beta testing: client applications should be ready to reconsider the tuning of these weight thresholds when upgrading to newer version of the PPL.
ppl_reset_deterministic_timeout
Resets the deterministic timeout so that the computation is not interrupted.
ppl_set_rounding_for_PPL
Sets the FPU rounding mode so that the PPL abstractions based on floating point numbers work correctly. This is performed automatically at initialization-time. Calling this function is needed only if restore_pre_PPL_rounding() has previously been called.
ppl_restore_pre_PPL_rounding
Sets the FPU rounding mode as it was before initialization of the PPL. After calling this function it is absolutely necessary to call set_rounding_for_PPL() before using any PPL abstractions based on floating point numbers. This is performed automatically at finalization-time.
ppl_irrational_precision(?Precision)
Unifies Precision with the precision parameter for irrational calculations.
ppl_set_irrational_precision(+Precision)
Sets the precision parameter for irrational calculations to Precision. In the following irrational calculations returning an unbounded rational (e.g., when computing a square root), the lesser between numerator and denominator will be limited to 2**Precision.
MIP problem handles identify independently owned objects. Copying produces a separate mutable problem. A handle remains valid through changes to that problem, including clear and swap, until explicit deletion or finalization. Malformed, unknown, deleted or wrong-type handles raise an invalid-argument exception before native access. Explicit deletion a second time is an error. Finalization releases MIP problems left allocated and permanently invalidates their handles; reinitialization does not revive them. Handle identities are independent of coefficient width. Constructors discard a new object if output unification fails or raises an exception.
ppl_is_mixed_integer_satisfiable(+Dimension, +Constraints, +Integers)
Succeeds exactly when the constraint list has a point in the explicit ambient space with the listed variable coordinates integral. Other coordinates remain real. Strict inequalities retain their membership meaning and all inputs are preserved. An empty constraint list denotes the universe in Dimension coordinates. Out-of-space constraint variables and integer indices are errors. This standalone predicate is available independently of selected domain types. Here we describe the predicates available for PPL objects defining mixed integer (linear) programming problems.
A strict inequality is admitted exactly when every coordinate with a nonzero coefficient has already been declared integer. Unused continuous coordinates do not prevent admission. Admitted strict rows are stored in integer-equivalent closed form: for example, 


The constructors taking a dimension and optionally constraints, objective and mode initially leave every coordinate real. To use nonconstant strict constraints, first create a problem with ppl_new_MIP_Problem_from_space_dimension/2, declare the required integer coordinates with ppl_MIP_Problem_add_to_integer_space_dimensions/2, then insert the constraints with ppl_MIP_Problem_add_constraint/2 or ppl_MIP_Problem_add_constraints/2. The input constraint terms are preserved. See Strict Constraints over Integer Coordinates for the native admission and normalization rules.
ppl_new_MIP_Problem_from_space_dimension(+Dimension_Type, -Handle)
Creates an MIP Problem 
Dimension_Type, objective function 
max. Handle is unified with the handle for 
ppl_new_MIP_Problem(+Dimension_Type, +Constraint_System, +Lin_Expr,
+Optimization_Mode, -Handle)
Creates an MIP Problem 
Dimension_Type, represented by Constraint_System, objective function Lin_Expr and optimization mode Optimization_Mode. Handle is unified with the handle for 
No coordinates are declared integer by this constructor, so any strict rows in Constraint_System must be constant. For nonconstant strict constraints, use the construction and declaration order in Strict Constraints over Integer Coordinates.
ppl_new_MIP_Problem_from_MIP_Problem(+Handle_1, -Handle_2)
Creates an MIP Problem 
Handle_1. Handle_2 is unified with the handle for 
ppl_MIP_Problem_swap(+Handle_1, +Handle_2)
Swaps the MIP Problem referenced by Handle_1 with the one referenced by Handle_2.
ppl_delete_MIP_Problem(+Handle)
Deletes the MIP Problem referenced by Handle. After execution, Handle is no longer a valid handle for a PPL MIP Problem.
ppl_MIP_Problem_space_dimension(+Handle, ?Dimension_Type)
Unifies the dimension of the vector space in which the MIP Problem referenced by Handle is embedded with Dimension_Type.
ppl_MIP_Problem_integer_space_dimensions(+Handle, ?Vars_List)
Unifies Vars_List with a list of variables representing the integer space dimensions of the MIP Problem referenced by Handle.
ppl_MIP_Problem_constraints(+Handle, -Constraint_System)
Unifies Constraint_System with a list of the constraints in the constraints system representing the feasible region for the MIP Problem referenced by Handle.
Admitted strict inequalities appear in their stored integer-equivalent closed form.
ppl_MIP_Problem_objective_function(+Handle, ?Lin_Expr)
Unifies Lin_Expr with the objective function for the MIP Problem referenced by Handle.
ppl_MIP_Problem_optimization_mode(+Handle, ?Optimization_Mode)
Unifies Optimization_Mode with the optimization mode for the MIP Problem referenced by Handle.
ppl_MIP_Problem_clear(+Handle)
Resets the MIP problem referenced by Handle to be the trivial problem with the feasible region the 

max.
ppl_MIP_Problem_add_space_dimensions_and_embed(
+Handle, +Dimension_Type)
Embeds the MIP problem referenced by Handle in a space that is enlarged by Dimension_Type dimensions.
ppl_MIP_Problem_add_to_integer_space_dimensions(+Handle, +Vars_List)
Updates the MIP Problem referenced by Handle so that the variables in Vars_List are added to the set of integer space dimensions.
Declare these dimensions before inserting strict inequalities that depend on them; see Strict Constraints over Integer Coordinates.
ppl_MIP_Problem_add_constraint(+Handle, +Constraint)
Updates the MIP Problem referenced by Handle so that the feasible region is represented by the original constraint system together with the constraint Constraint.
A strict inequality must satisfy the integer-support condition in Strict Constraints over Integer Coordinates and is stored in equivalent closed form. A strict row depending on a continuous coordinate is rejected through the interface's invalid-argument exception mechanism. The input constraint term is preserved.
ppl_MIP_Problem_add_constraints(+Handle, +Constraint_System)
Updates the MIP Problem referenced by Handle so that the feasible region is represented by the original constraint system together with all the constraints in Constraint_System.
Every strict inequality must satisfy the integer-support condition in Strict Constraints over Integer Coordinates and is stored in equivalent closed form. A strict row depending on a continuous coordinate is rejected through the interface's invalid-argument exception mechanism. The input constraint terms are preserved.
ppl_MIP_Problem_set_objective_function(+Handle, +Lin_Expr)
Updates the MIP Problem referenced by Handle so that the objective function is changed to Lin_Expr.
ppl_MIP_Problem_set_control_parameter(+Handle, +Control_Parameter_Value)
Updates the MIP Problem referenced by Handle so that the value for the relevant control parameter name is changed to Control_Parameter_Value.
ppl_MIP_Problem_get_control_parameter(+Handle, +Control_Parameter_Name,
?Control_Parameter_Value)
Unifies Control_Parameter_Value with the value of the control parameter Control_Parameter_Name.
ppl_MIP_Problem_set_optimization_mode(+Handle, +Optimization_Mode)
Updates the MIP Problem referenced by Handle so that the optimization mode is changed to Optimization_Mode.
ppl_MIP_Problem_is_satisfiable(+Handle)
Succeeds if and only if the MIP Problem referenced by Handle is satisfiable.
ppl_MIP_Problem_solve(+Handle, ?MIP_Problem_Status)
Solves the MIP problem referenced by Handle and unifies MIP_Problem_Status with: unfeasible, if the MIP problem is not satisfiable; unbounded, if the MIP problem is satisfiable but there is no finite bound to the value of the objective function; optimized, if the MIP problem admits an optimal solution.
ppl_MIP_Problem_feasible_point(+Handle, ?Generator)
Unifies Generator with a feasible point for the MIP problem referenced by Handle.
ppl_MIP_Problem_optimizing_point(+Handle, ?Generator)
Unifies Generator with an optimizing point for the MIP problem referenced by Handle.
ppl_MIP_Problem_optimal_value(+Handle, ?Coeff_1, ?Coeff_2)
Unifies Coeff_1 and Coeff_2 with the numerator and denominator, respectively, for the optimal value for the MIP problem referenced by Handle.
ppl_MIP_Problem_evaluate_objective_function(+Handle, +Generator,
?Coeff_1, ?Coeff_2)
Evaluates the objective function of the MIP problem referenced by Handle at point Generator. Coefficient_1 is unified with the numerator and Coefficient_2 is unified with the denominator of the objective function value at Generator.
ppl_MIP_Problem_OK(+Handle)
Succeeds only if the MIP Problem referenced by Handle is well formed, i.e., if it satisfies all its implementation invariants. Useful for debugging purposes.
ppl_MIP_Problem_ascii_dump(+Handle)
Dumps an ascii representation of the PPL internal state for the MIP problem referenced by Handle on the standard output.
Here we describe some functions available for PPL objects defining parametric integer programming problems.
All problem variables and parameters range over nonnegative integers. Constraints involving only parameters define the initial context. For each parameter assignment in that context, the solver computes the lexicographic minimum of the feasible variable vectors, when one exists. The solution tree describes these parameter-dependent minima and the parameter regions with no feasible solution.
ppl_new_PIP_Problem_from_space_dimension(+Dimension_Type, -Handle)
Creates a PIP Problem 
Dimension_Type, with no explicit constraints and no parameters. Every coordinate is a nonnegative integer, and the lexicographic minimum is the origin. Handle is unified with the handle for 
ppl_new_PIP_Problem_from_PIP_Problem(+Handle_1, -Handle_2)
Creates a PIP Problem 
Handle_1. Handle_2 is unified with the handle for 
ppl_new_PIP_Problem(+Dimension_Type, +Constraint_System, +Vars_List,
-Handle)
Creates a PIP Problem 
Dimension_Type, with constraints Constraint_System and parameter dimensions selected by Vars_List. All coordinates, including parameters, are implicitly restricted to nonnegative integers. Handle is unified with the handle for 
ppl_PIP_Problem_swap(+Handle_1, +Handle_2)
Swaps the PIP Problem referenced by Handle_1 with the one referenced by Handle_2.
ppl_delete_PIP_Problem(+Handle)
Deletes the PIP Problem referenced by Handle. After execution, Handle is no longer a valid handle for a PPL PIP Problem.
ppl_PIP_Problem_space_dimension(+Handle, ?Dimension_Type)
Unifies the dimension of the vector space in which the PIP Problem referenced by Handle is embedded with Dimension_Type.
ppl_PIP_Problem_parameter_space_dimensions(+Handle, ?Vars_List)
Unifies Vars_List with a list of variables representing the parameter space dimensions of the PIP Problem referenced by Handle.
ppl_PIP_Problem_constraints(+Handle, ?Constraint_System)
Unifies Constraint_System with a list of the constraints in the constraints system representing the feasible region for the PIP Problem referenced by Handle.
ppl_PIP_Problem_get_control_parameter(+Handle, +Control_Parameter_Name,
?Control_Parameter_Value)
Unifies Control_Parameter_Value with the value of the control parameter Control_Parameter_Name.
ppl_PIP_Problem_clear(+Handle)
Resets the PIP problem referenced by Handle to be the trivial problem with the feasible region the 
ppl_PIP_Problem_add_space_dimensions_and_embed(
+Handle, +Dimension_Type1, +Dimension_Type2)
Embeds the PIP problem referenced by handle in a space that is enlarged by dimension1 non-parameter dimensions and dimension2 parameter dimensions.
ppl_PIP_Problem_add_to_parameter_space_dimensions(+Handle, +Vars_List)
Updates the PIP Problem referenced by Handle so that the variables in Vars_List are added to the set of parameter space dimensions.
ppl_PIP_Problem_add_constraint(+Handle, +Constraint)
Updates the PIP Problem referenced by Handle so that the feasible region is represented by the original constraint system together with the constraint Constraint.
ppl_PIP_Problem_add_constraints(+Handle, +Constraint_System)
Updates the PIP Problem referenced by Handle so that the feasible region is represented by the original constraint system together with all the constraints in Constraint_System.
ppl_PIP_Problem_set_control_parameter(+Handle, +Control_Parameter_Value)
Updates the PIP Problem referenced by Handle so that the value for the relevant control parameter name is changed to Control_Parameter_Value.
With the interface initialized, the following query selects the cutting_strategy_all value, reads it back into Strategy, and deletes the problem:
When a big parameter is designated, the native solver treats it as arbitrarily large. The satisfiability and solve predicates then follow those sign assumptions. A finite parameter assignment used to interpret a returned tree must satisfy the initial context and those assumptions. Infeasibility in the big-parameter mode can coexist with a feasible finite assignment outside that scope.
ppl_PIP_Problem_is_satisfiable(+Handle)
Succeeds exactly for the optimized status in the selected mode.
ppl_PIP_Problem_solve(+Handle, ?PIP_Problem_Status)
Solves the PIP problem referenced by Handle and unifies PIP_Problem_Status with: unfeasible for infeasibility in the selected mode, or optimized when the solver produces an optimal solution tree.
PIP problem and tree handles are opaque typed terms checked by an owner/generation registry. Their predicate names, arities and modes are unchanged. The former raw-address representation is no longer accepted; applications must pass handles back to interface predicates without inspecting or constructing their representation. Handle identities do not depend on the configured coefficient width and are never reused within a loaded foreign module. Exhausting the identity or engine-integer range raises a length error. Handles cannot be saved for use in another process or after unloading and reloading the foreign module.
A tree handle borrows storage from its problem; it does not own a copy of the tree. Clearing a problem, adding constraints or dimensions, changing its parameter dimensions, big parameter or solver controls, and swapping it invalidate all its existing root, descendant and bottom handles. Swap invalidates both problem identities, including a self-swap. Invalidation occurs after input term conversion and before native mutation; it remains effective if that mutation does nothing or throws. A rejected input term before native mutation preserves existing handles. Obtain a fresh root and traverse it after an invalidating call.
Queries preserve handles, including repeated solution, optimizing-solution, solve and satisfiability queries on an unchanged solved problem. Repeated queries for the same root or child produce the same handle within its current generation. Constraints, affine expressions and artificial-parameter lists returned as Prolog values are independent copies.
Deleting a problem releases its native storage and invalidates its problem and tree handles. Finalizing the interface releases all remaining PIP problems and invalidates their handles; reinitialization never makes old handles valid again. Backtracking or Prolog term collection alone does not delete a problem. Stale, malformed, unknown or wrong-type PIP handles raise ppl_invalid_argument before native storage is accessed, including on repeated deletion. Bottom is a valid handle for the three node-kind predicates: is_bottom succeeds and is_solution and is_decision fail. Dereferencing bottom or requesting a child or parametric value from a node of the wrong kind raises ppl_invalid_argument.
ppl_PIP_Problem_solution(+Handle, ?PIP_Tree_Node)
Solves the PIP problem referenced by Handle and unifies PIP_Tree_Node with a handle to its solution tree, or a handle representing bottom for the infeasible status in the selected mode.
ppl_PIP_Problem_optimizing_solution(+Handle, ?PIP_Tree_Node)
Solves the PIP problem referenced by Handle and unifies PIP_Tree_Node with a handle to its optimizing solution tree, or a handle representing bottom for the infeasible status in the selected mode.
ppl_PIP_Problem_has_big_parameter_dimension(+Handle, ?Dimension_Type)
Succeeds if and only if the PIP Problem referenced by Handle has a designated big parameter and Dimension_Type unifies with its coordinate index. Fails if no big parameter is set or the supplied dimension does not unify with that index.
ppl_PIP_Problem_set_big_parameter_dimension(+Handle, +Dimension_Type)
Updates the PIP Problem referenced by Handle so that the dimension for the big parameter is Dimension_Type.
ppl_PIP_Problem_OK(+Handle)
Succeeds only if the PIP Problem referenced by Handle is well formed, i.e., if it satisfies all its implementation invariants. Useful for debugging purposes.
ppl_PIP_Problem_ascii_dump(+Handle)
Dumps an ascii representation of the PPL internal state for the PIP problem referenced by Handle on the standard output.
ppl_PIP_Tree_Node_constraints(+Handle, ?Constraint_System)
Unifies Constraint_System with a list of the parameter constraints in the PIP tree node referenced by Handle.
ppl_PIP_Tree_Node_is_solution(+Handle)
Succeeds if and only if handle represents a solution node.
ppl_PIP_Tree_Node_is_decision(+Handle)
Succeeds if and only if handle represents a decision node.
ppl_PIP_Tree_Node_is_bottom(+Handle)
Succeeds if and only if handle represents bottom.
ppl_PIP_Tree_Node_artificials(+Handle, ?Artificial_Parameter_List)
Unifies Artificial_Parameter_List with a list of the artificial parameters in the PIP tree node referenced by Handle, in native introduction order. Their coordinate indices follow the original coordinates and the artificial parameters inherited from ancestor nodes.
ppl_PIP_Tree_Node_OK(+Handle)
Succeeds only if the PIP tree node referenced by Handle is well formed, i.e., if it satisfies all its implementation invariants. Useful for debugging purposes.
ppl_PIP_Tree_Node_parametric_values(+Handle, +Var, ?Lin_Expr)
Unifies Lin_Expr with a linear expression representing the values of problem variable Var in the solution node represented by Handle. The linear expression may involve problem parameters as well as artificial parameters.
ppl_PIP_Tree_Node_true_child(+Handle1, ?Handle2)
If the PIP_Tree_Node represented by Handle1 is a decision node unifies the PIP tree node referenced by Handle2 with the child on the true branch of the PIP tree node represented by Handle1. An exception is thrown if this is not a decision node.
ppl_PIP_Tree_Node_false_child(+Handle1, ?Handle2)
If the PIP_Tree_Node represented by Handle1 is a decision node unifies the PIP tree node referenced by Handle2 with the child on the false branch of the PIP tree node represented by Handle1. An exception is thrown if this is not a decision node.