Crate rooc

Source
Expand description

§ROOC

ROOC is a modeling language for defining and solving optimization problems.

Write everything as a single source file:

use indexmap::IndexMap;
use rooc::pipe::{AutoSolverPipe, LinearModelPipe, ModelPipe, PipeContext, PipeRunner, PipeableData, PreModelPipe};
let source = "
max sum((value, i) in enumerate(values)) { value * x_i }
s.t.
   sum((weight, i) in enumerate(weights)) { weight * x_i } <= capacity
where
   let weights = [10, 60, 30, 40, 30, 20, 20, 2]
   let values = [1, 10, 15, 40, 60, 90, 100, 15]
   let capacity = 102
define
   x_i as Boolean for i in 0..len(weights)";
//use pipes to solve the problem
let pipe_runner = PipeRunner::new(vec![
   Box::new(rooc::pipe::CompilerPipe::new()),
   Box::new(PreModelPipe::new()),
   Box::new(ModelPipe::new()),
   Box::new(LinearModelPipe::new()),
   Box::new(AutoSolverPipe::new()),
]);
let result = pipe_runner
   .run(
       PipeableData::String(source.to_string()),
       &PipeContext::new(vec![], &IndexMap::new()),
   )
   .unwrap();
let last = result
   .into_iter()
   .last()
   .unwrap()
   .to_milp_solution()
       .unwrap();

println!("{}", last)

Or extend the language with your own functionality and data

Modules§

binary_solver
block_functions
builtin_primitive_traits_impl
common
consts
domain_declaration
function_traits
functions
graph
il
il_exp
il_problem
iterable
iterable_set
iterable_utils
linear_integer_binary_solver
linear_model
linearizer
math_enums
math_utils
model_transformer
operators
optimal_tableau
pipe
pre_model
primitive
primitive_traits
real_solver
rules_parser
simplex
simplex_enums
simplex_solver
simplex_utils
standard_linear_model
standardizer
tableau
tuple
type_checker

Macros§

bail_missing_token
bail_semantic_error
bail_wrong_argument
check_bounds
enum_with_variants_to_string
err_unexpected_token
make_pipe_error
match_or_bail
match_pipe_data_to
wrong_argument

Structs§

AddressableAccess
Represents array-like access to a variable, such as x[1][2].
Assignment
Represents a variable assignment in a solution.
BlockFunction
A function that operates on a fixed set of expressions. This represents functions like min, max, avg that take a set of arguments and compute a single result.
BlockScopedFunction
A function that operates over a set of values with iteration variables. This represents functions like sum, product, etc. that iterate over a set.
CompilationError
Represents a compilation error with location information and error details.
CompoundVariable
Represents a variable with subscript indices, such as x_1_2.
Constant
A constant value with a name and a value
EqualityConstraint
Represents a linear equality constraint in standard form: ax = b where a is a vector of coefficients and b is a constant.
FunctionCall
Represents a function call with its arguments, name and source span.
Graph
GraphEdge
GraphNode
InputSpan
Represents a span of text in the input source, tracking location information.
IterableSet
Represents an iterable set expression in the intermediate language.
LinearConstraint
Represents a linear constraint in the form: coefficients * variables comparison_operator rhs
LinearModel
Represents a complete linear programming model including variables, constraints, and objective function.
Linearizer
Manages the linearization process for expressions and constraints.
LpSolution
Represents a solution to a linear programming problem.
NormalizationContext
Context for tracking the normalization process of converting constraints to standard form.
OptimalTableau
OptimalTableauWithSteps
PreConstraint
Represents a constraint in a mathematical programming problem.
PreObjective
Represents an optimization objective in a mathematical programming problem.
RoocParser
A parser for the Rooc optimization modeling language.
RoocSolver
SimplexStep
Spanned
A wrapper type that associates a value with its location in source code.
StandardLinearModel
Represents a linear optimization model in standard form.
Tableau
Tuple
A tuple type that holds an ordered collection of Primitive values.

Enums§

BinOp
BlockFunctionKind
BlockScopedFunctionKind
CanonicalTransformError
Comparison
IntOrBoolValue
Represents a variable value that can be either boolean or integer.
IterableKind
Represents different types of iterable collections in the system.
LinearModelError
Errors that can occur when manipulating a LinearModel.
LinearizationError
MILPValue
Represents a variable value that can be either boolean or integer.
Operator
OperatorError
Represents errors that can occur during operator application.
OptimizationType
ParseError
Represents different types of parsing errors that can occur during compilation.
PreExp
Represents an expression in the intermediate language before final transformation.
PreVariableType
Represents the type of a variable before type checking and transformation
Primitive
Represents a primitive value in the system.
PrimitiveKind
RoocSolverError
SimplexError
SolverError
Represents errors that can occur during linear programming problem solving.
StepAction
UnOp
VariableType
Represents the final, resolved type of a variable after being compiled

Traits§

ApplyOp
Trait for types that can have operators applied to them.
RoocFunction
Trait defining the interface for Rooc functions.
Spreadable
Trait for types that can be spread into a sequence of primitives.

Functions§

auto_solver
Solves a any kind of linear programming problem by picking the right solver for the model.
default_rooc_function_to_latex
Converts a function call to LaTeX format.
default_rooc_function_to_string
Converts a function call to a string representation.
default_type_check
The default type check implementation, it performs type checking of function arguments against expected types.
default_wrong_number_of_arguments
Creates an error for wrong number of arguments.
default_wrong_type
Creates a type error for wrong argument types.
divide_matrix_row_by
find_invalid_variables
Finds variables in a domain that don’t satisfy a validation condition.
float_eq
Checks if two numbers are the same within 5 decimal digits
float_ne
Checks if two numbers are different within 5 decimal digits
format_var
Formats a variable term with its coefficient for display.
make_constraints_map_from_assignment
normalize_constraint
Converts a linear constraint to standard form by adding slack or surplus variables as needed.
process_variables
Processes coefficients and variables to create Times expressions, filtering based on index.
process_variables_binary
Similar to process_variables but works with binary variables.
solve_binary_lp_problem
Solves a binary linear programming problem.
solve_integer_binary_lp_problem
Solves a mixed integer-binary linear programming problem.
solve_milp_lp_problem
Solves a mixed-integer linear programming problem using the MicroLP solver.
solve_real_lp_problem_clarabel
Solves a linear programming problem with real variables using the Clarabel solver.
solve_real_lp_problem_micro_lp
Solves a linear programming problem with real variables using the microlp solver.
solve_real_lp_problem_slow_simplex
Solves a linear programming problem with real variables using a basic simplex algorithm.
to_standard_form
Converts a linear programming model into standard form.

Type Aliases§

FunctionContextMap