protocol

linear_programming_protocol

Protocol for immutable linear-program construction, solving, and result inspection.

Availability:
logtalk_load(linear_programming(loader))
Author: Paulo Moura
Version: 1:0:0
Date: 2026-09-03
Compilation flags:
static
Dependencies:
(none)
Remarks:
(none)
Inherited public predicates:
(none)

Public predicates

new_problem/1

Creates an empty linear-program problem.

Compilation flags:
static
Template:
new_problem(Problem)
Mode and number of proofs:
new_problem(-compound) - one

variable/4

Adds a variable with default bounds. Continuous and integer variables default to zero and positive infinity; binary variables default to zero and one. The variable type is continuous, integer, or binary.

Compilation flags:
static
Template:
variable(Name,Type,Problem0,Problem)
Mode and number of proofs:
variable(+term,+atom,+compound,-compound) - one_or_error
Exceptions:
An argument is insufficiently instantiated:
instantiation_error
Problem0 is not a linear-program problem:
type_error(linear_program,Problem0)
Type is not a supported variable type:
domain_error(linear_programming_variable_type,Type)
Name is already declared:
domain_error(linear_programming_variable,Name)

variable/6

Adds a variable with explicit lower and upper bounds. A bound is a number, inf, or -inf as appropriate.

Compilation flags:
static
Template:
variable(Name,Type,Lower,Upper,Problem0,Problem)
Mode and number of proofs:
variable(+term,+atom,+term,+term,+compound,-compound) - one_or_error
Exceptions:
An argument is insufficiently instantiated:
instantiation_error
Problem0 is not a linear-program problem:
type_error(linear_program,Problem0)
Type is not a supported variable type:
domain_error(linear_programming_variable_type,Type)
Name is already declared:
domain_error(linear_programming_variable,Name)
The bounds are invalid or inconsistent:
domain_error(linear_programming_bounds,Lower-Upper)

constraint/5

Adds a linear constraint. Coefficients is a list of Coefficient*Variable terms and Sense is =<, >=, or =.

Compilation flags:
static
Template:
constraint(Coefficients,Sense,RightHandSide,Problem0,Problem)
Mode and number of proofs:
constraint(+list(compound),+atom,+number,+compound,-compound) - one_or_error
Exceptions:
An argument is insufficiently instantiated:
instantiation_error
Problem0 is not a linear-program problem:
type_error(linear_program,Problem0)
Coefficients is not a list of coefficient-variable terms:
type_error(linear_expression,Coefficients)
Sense is not a supported constraint sense:
domain_error(linear_programming_constraint_sense,Sense)
A coefficient references an undeclared variable:
domain_error(linear_programming_variable,Variable)

constraints/3

Adds a list of constraint(Coefficients, Sense, RightHandSide) terms.

Compilation flags:
static
Template:
constraints(Constraints,Problem0,Problem)
Mode and number of proofs:
constraints(+list(compound),+compound,-compound) - one_or_error
Exceptions:
An argument is insufficiently instantiated:
instantiation_error
Constraints is not a list of valid constraint terms:
type_error(linear_programming_constraints,Constraints)
Problem0 is not a linear-program problem:
type_error(linear_program,Problem0)

objective/4

Sets the linear objective. Coefficients is a list of Coefficient*Variable terms and Sense is minimize or maximize.

Compilation flags:
static
Template:
objective(Coefficients,Sense,Problem0,Problem)
Mode and number of proofs:
objective(+list(compound),+atom,+compound,-compound) - one_or_error
Exceptions:
An argument is insufficiently instantiated:
instantiation_error
Problem0 is not a linear-program problem:
type_error(linear_program,Problem0)
Coefficients is not a list of coefficient-variable terms:
type_error(linear_expression,Coefficients)
Sense is not a supported objective sense:
domain_error(linear_programming_objective_sense,Sense)
The problem already has an objective:
domain_error(linear_programming_objective,Problem0)
A coefficient references an undeclared variable:
domain_error(linear_programming_variable,Variable)

problem_from_matrices/8

Creates a problem from a dense objective vector, objective sense, equality rows and right-hand sides, less-than-or-equal rows and right-hand sides, and variable bounds. Variables are named by their one-based column indices.

Compilation flags:
static
Template:
problem_from_matrices(Objective,ObjectiveSense,EqualityMatrix,EqualityRightHandSide,InequalityMatrix,InequalityRightHandSide,Bounds,Problem)
Mode and number of proofs:
problem_from_matrices(+list(number),+atom,+list(list(number)),+list(number),+list(list(number)),+list(number),+list(pair),-compound) - one_or_error
Exceptions:
An argument is insufficiently instantiated:
instantiation_error
The matrix and vector dimensions are inconsistent:
domain_error(linear_programming_dimensions,Objective)
An input is not a numeric vector, numeric matrix, or valid bounds list:
type_error(linear_programming_matrix_problem,Objective)

solve/2

Solves a linear-program problem using default options and returns a result term. Solver statuses include optimal, infeasible, unbounded, iteration_limit, node_limit, and numerical_error as applicable to the backend.

Compilation flags:
static
Template:
solve(Problem,Result)
Mode and number of proofs:
solve(+compound,-compound) - one_or_error
Exceptions:
Problem is a variable:
instantiation_error
Problem is not a linear-program problem:
type_error(linear_program,Problem)
Problem has no variables:
domain_error(linear_programming_problem,empty)
Problem has no objective:
domain_error(linear_programming_problem,missing_objective)
Problem contains a variable type unsupported by the backend:
domain_error(simplex_variable_type,Variable-Type)
A discrete variable does not have finite bounds:
domain_error(milp_finite_integer_bounds,Variable-(Lower-Upper))
A discrete variable domain contains no integer:
domain_error(milp_integer_domain,Variable-(Lower-Upper))

solve/3

Solves a linear-program problem using the specified options and returns a result term. Solver statuses include optimal, infeasible, unbounded, iteration_limit, node_limit, and numerical_error as applicable to the backend.

Compilation flags:
static
Template:
solve(Problem,Result,Options)
Mode and number of proofs:
solve(+compound,-compound,+list(compound)) - one_or_error
Exceptions:
Problem is a variable:
instantiation_error
Problem is not a linear-program problem:
type_error(linear_program,Problem)
Problem has no variables:
domain_error(linear_programming_problem,empty)
Problem has no objective:
domain_error(linear_programming_problem,missing_objective)
Problem contains a variable type unsupported by the backend:
domain_error(simplex_variable_type,Variable-Type)
A discrete variable does not have finite bounds:
domain_error(milp_finite_integer_bounds,Variable-(Lower-Upper))
A discrete variable domain contains no integer:
domain_error(milp_integer_domain,Variable-(Lower-Upper))
Options is a variable:
instantiation_error
Options is neither a variable nor a list:
type_error(list,Options)
An element Option of the list Options is a variable:
instantiation_error
An element Option of the list Options is neither a variable nor a compound term:
type_error(compound,Option)
An element Option of the list Options is a compound term but not a valid option:
domain_error(option,Option)

status/2

Returns the result status.

Compilation flags:
static
Template:
status(Result,Status)
Mode and number of proofs:
status(+compound,-atom) - one_or_error
Exceptions:
Result is a variable:
instantiation_error
Result is not a linear-programming result:
type_error(linear_programming_result,Result)

objective_value/2

Returns the optimal objective value. Fails when the result status is not optimal.

Compilation flags:
static
Template:
objective_value(Result,Value)
Mode and number of proofs:
objective_value(+compound,-number) - zero_or_one_or_error
Exceptions:
Result is a variable:
instantiation_error
Result is not a linear-programming result:
type_error(linear_programming_result,Result)

variable_value/3

Returns an optimal variable value. Fails when the result status is not optimal or the variable is absent.

Compilation flags:
static
Template:
variable_value(Result,Variable,Value)
Mode and number of proofs:
variable_value(+compound,+term,-number) - zero_or_one_or_error
Exceptions:
Result is a variable:
instantiation_error
Result is not a linear-programming result:
type_error(linear_programming_result,Result)

statistics/2

Returns solver statistics stored in a result.

Compilation flags:
static
Template:
statistics(Result,Statistics)
Mode and number of proofs:
statistics(+compound,-list(compound)) - one_or_error
Exceptions:
Result is a variable:
instantiation_error
Result is not a linear-programming result:
type_error(linear_programming_result,Result)


Protected predicates

(none)

Private predicates

(none)

Operators

(none)