Struct lpsolve::Problem
[−]
[src]
pub struct Problem { /* fields omitted */ }
A linear programming problem.
Methods
impl Problem
[src]
fn new(rows: c_int, cols: c_int) -> Option<Problem>
Initialize an empty problem with space for rows
and cols
.
fn read_lp<P: Deref<Target = CStr>, C: Deref<Target = CStr>>(
path: &P,
verbosity: Verbosity,
initial_name: &C
) -> Option<Problem>
path: &P,
verbosity: Verbosity,
initial_name: &C
) -> Option<Problem>
Reads an lp-format model from path
.
fn read_freemps<P: Deref<Target = CStr>>(
path: &P,
options: MPSOptions
) -> Option<Problem>
path: &P,
options: MPSOptions
) -> Option<Problem>
Read an mps-format model from path
using the "free" formatting.
fn read_fixedmps<P: Deref<Target = CStr>>(
path: &P,
options: MPSOptions
) -> Option<Problem>
path: &P,
options: MPSOptions
) -> Option<Problem>
Read an mps-format model from path
using the fixed formatting.
fn write_lp(&self, out: &mut Write) -> bool
Write an lp-format model into out
.
If there are any errors writing to out
, false
will be returned. Otherwise, true
.
fn write_fixedmps(&self, out: &mut Write) -> bool
Write an mps-format model into out
using the fixed formatting.
If there are any errors writing to out
, false
will be returned. Otherwise, true
.
fn write_freemps(&self, out: &mut Write) -> bool
Write an mps-format model into out
using the "free" formatting.
If there are any errors writing to out
, false
will be returned. Otherwise, true
.
fn write_mps(&self, out: &mut Write, formatting: c_int) -> bool
Write an mps-format model into out
using formatting
.
If there are any errors writing to out
, false
will be returned. Otherwise, true
.
formatting
must be 1 for fixed or 2 for free.
fn resize(&mut self, rows: c_int, cols: c_int) -> bool
Reserve enough memory for rows
and cols
.
If rows
or cols
are less than the current number of rows or columns, the additional
rows and columns will be deleted.
Returns true
if successful.
fn add_column(&mut self, values: &[f64]) -> bool
Add a column to the model.
If values
is empty, an all-zero column will be added.
This will assert that values
has at least as many elements as the underlying model.
fn add_column_scatter(&mut self, values: &[f64], indices: &[c_int]) -> bool
Add a column to the model, scattering values
by indices
.
The values for the column are taken from values
. The value from values[i]
will be
placed into row indices[i]
. The length used is the max of the lengths of values
and
indices
. There is a debug_assert that these are equal.
fn get_column(&self, values: &mut [f64], column: c_int) -> bool
Read a column from the model.
fn get_row(&self, values: &mut [f64], row: c_int) -> bool
Read a row from the model.
fn add_constraint(
&mut self,
coeffs: &[f64],
target: f64,
kind: ConstraintType
) -> bool
&mut self,
coeffs: &[f64],
target: f64,
kind: ConstraintType
) -> bool
Add a constraint to the model.
The constraint is that coeffs * vars OP target
, where OP
is specified by kind
.
For optimal performance, use the matrix_builder
method and add the objective function
first. This method is otherwise very slow for large models.
Asserts that coeffs
has at least as many elements as the underlying model.
fn add_sos_constraint(
&mut self,
name: &CStr,
sostype: SOSType,
priority: c_int,
weights: &[f64],
variables: &[c_int]
) -> bool
&mut self,
name: &CStr,
sostype: SOSType,
priority: c_int,
weights: &[f64],
variables: &[c_int]
) -> bool
Add a Special Ordered Set constraint.
The weights
are scattered by variables
, that is, weights[i]
will be specified for
column variables[i]
.
The length used is the max of the lengths of values
and indices
. There is a
debug_assert that these are equal.
fn del_column(&mut self, col: c_int) -> bool
Delete a column from the model.
The other columns are shifted leftward. col
cannot be 0, as that column represents the
RHS, which must always be present.
fn del_constraint(&mut self, row: c_int) -> bool
Delete a constraint from the model.
The other constraints are shifted upwards. row
cannot be 0, as that row represents the
objective function, which must always be present.
fn is_negative(&self, col: c_int) -> Option<bool>
Returns Some(true)
if the specified column can be negative, Some(false)
otherwise.
If the column is out-of-bounds, None
is returned.
fn set_variable_type(&mut self, col: c_int, vartype: VarType) -> bool
Set a variable to be either binary or floating point.
fn get_variable_type(&self, col: c_int) -> Option<VarType>
Get the type of a variable, None
if col
is out of bounds.
fn set_bounds(&mut self, col: c_int, lower: f64, upper: f64) -> bool
Set the upper and lower bounds of a variable.
fn set_bounds_mode(&mut self, tighten: BoundsMode)
Set the bounds mode to 'tighten'.
If the bounds mode is true
, then when set_bounds
, set_lower_bound
, or
set_upper_bound
is used and the provided bound is less restrictive than the current bound
(ie, its absolute value is larger), then the request will be ignored. However, if the new
bound is more restrictive (ie, its absolute value is smaller) the request will go through.
If the bounds mode is false
, the bounds will always be set as specified.
fn get_bounds_mode(&self) -> BoundsMode
Get the bounds mode.
See set_bounds_mode
for what this value means.
fn set_constraint_type(&mut self, row: c_int, contype: ConstraintType) -> bool
Set the type of a constraint.
fn get_constraint_type(&self, row: c_int) -> Option<ConstraintType>
Get the type of a constraint, or None
if out of bounds or another error occurs.
fn set_unbounded(&mut self, col: c_int) -> bool
Set a variable to be unbounded.
fn is_unbounded(&self, col: c_int) -> Option<bool>
Check if a variable is unbounded.
fn set_infinite(&mut self, infinity: f64)
Set the practical value for "infinite"
This is the bound of the absolute value of all variables. If the absolute value of a variable is larger than this, it is considered to have diverged.
fn get_infinite(&self) -> f64
Get the value of "infinite"
See set_infinite for more details.
fn set_integer(&mut self, col: c_int, must_be_integer: bool) -> bool
Set a variable's integer type.
fn is_integer(&self, col: c_int) -> Option<bool>
Check if a variable is an integer.
fn set_objective_function(&mut self, coeffs: &[f64]) -> bool
Sets the objective function.
Asserts that coeffs
has at least as many elements as the underlying model.
fn scatter_objective_function(
&mut self,
coeffs: &[f64],
indices: &[c_int]
) -> bool
&mut self,
coeffs: &[f64],
indices: &[c_int]
) -> bool
Scatters coeffs
into the objective function coefficients with indices
.
The length used is the max of the lengths of coeffs
and indices
. There is a
debug_assert that these are equal.
fn set_constraint_range(&mut self, row: c_int, range: f64) -> bool
Sets the range of a constraint.
If the constraint type is <=
, then the "actual" constraint will be RHS - range <= v <= RHS
.
If the constraint type is >=
, then the "actual" constraint will be RHS <= v <= RHS + range
.
This puts a bound on the constraint and can give the solver more freedom, and is more efficient than adding an extra constraint.
fn get_constraint_range(&self, row: c_int) -> Option<f64>
Get the range on a constraint if one is set, otherwise None
.
fn solve(&mut self) -> SolveStatus
Solve the model.
fn get_solution_variables<'a>(
&self,
vars: &'a mut [f64]
) -> Option<&'a mut [f64]>
&self,
vars: &'a mut [f64]
) -> Option<&'a mut [f64]>
Read out the values assigned to variables from the most recent solve
.
Returns None
if vars
does not have at least as many elements as the underlying model
has columns. Otherwise, returns Some
with the slice truncated to the number of columns.
unsafe fn from_lprec(lprec: *mut lprec) -> Problem
Construct a wrapper for a pre-existing lprec
.
This is unsafe as the pointer is not null-checked etc.
fn to_lprec(&self) -> *mut lprec
Get the lprec
that this wraps.
Don't delete_lp
it, please.
fn num_cols(&self) -> c_int
fn num_rows(&self) -> c_int
Trait Implementations
impl Drop for Problem
[src]
impl Clone for Problem
[src]
fn clone(&self) -> Problem
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more