09.02.2015 Views

Sage Reference Manual: Numerical Optimization - Mirrors

Sage Reference Manual: Numerical Optimization - Mirrors

Sage Reference Manual: Numerical Optimization - Mirrors

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Numerical</strong> <strong>Optimization</strong>, Release 6.1.1<br />

sage: p.add_variable(binary=True)<br />

1<br />

sage: p.add_variable(lower_bound=-2.0, integer=True)<br />

2<br />

sage: p.add_variable(continuous=True, integer=True)<br />

Traceback (most recent call last):<br />

...<br />

ValueError: ...<br />

sage: p.add_variable(name=’x’,obj=1.0)<br />

3<br />

sage: p.col_name(3)<br />

’x’<br />

sage: p.objective_coefficient(3)<br />

1.0<br />

add_variables(number, lower_bound=0.0, upper_bound=None, binary=False, continuous=False,<br />

integer=False, obj=0.0, names=None)<br />

Add number new variables.<br />

This amounts to adding new columns to the matrix. By default, the variables are both positive, real and<br />

theor coefficient in the objective function is 0.0.<br />

INPUT:<br />

•n - the number of new variables (must be > 0)<br />

•lower_bound - the lower bound of the variable (default: 0)<br />

•upper_bound - the upper bound of the variable (default: None)<br />

•binary - True if the variable is binary (default: False).<br />

•continuous - True if the variable is binary (default: True).<br />

•integer - True if the variable is binary (default: False).<br />

•obj - (optional) coefficient of all variables in the objective function (default: 0.0)<br />

•names - optional list of names (default: None)<br />

OUTPUT: The index of the variable created last.<br />

EXAMPLE:<br />

sage: from sage.numerical.backends.generic_backend import get_solver<br />

sage: p = get_solver(solver = "GLPK")<br />

sage: p.ncols()<br />

0<br />

sage: p.add_variables(5)<br />

4<br />

sage: p.ncols()<br />

5<br />

sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=[’a’,’b’])<br />

6<br />

col_bounds(index)<br />

Return the bounds of a specific variable.<br />

INPUT:<br />

•index (integer) – the variable’s id.<br />

OUTPUT:<br />

64 Chapter 5. LP Solver backends

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!