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 />

base_ring()<br />

Return the base ring.<br />

OUTPUT:<br />

A ring. The coefficients that the chosen solver supports.<br />

EXAMPLES:<br />

sage: p = MixedIntegerLinearProgram(solver=’GLPK’)<br />

sage: p.base_ring()<br />

Real Double Field<br />

sage: p = MixedIntegerLinearProgram(solver=’ppl’)<br />

sage: p.base_ring()<br />

Rational Field<br />

constraints(indices=None)<br />

Returns a list of constraints, as 3-tuples.<br />

INPUT:<br />

•indices – select which constraint(s) to return<br />

OUTPUT:<br />

–If indices = None, the method returns the list of all the constraints.<br />

–If indices is an integer i, the method returns constraint i.<br />

–If indices is a list of integers, the method returns the list of the corresponding constraints.<br />

Each constraint is returned as a triple lower_bound, (indices, coefficients),<br />

upper_bound. For each of those entries, the corresponding linear function is the one associating<br />

to variable indices[i] the coefficient coefficients[i], and 0 to all the others.<br />

lower_bound and upper_bound are numerical values.<br />

EXAMPLE:<br />

First, let us define a small LP:<br />

sage: p = MixedIntegerLinearProgram()<br />

sage: p.add_constraint(p[0] - p[2], min = 1, max = 4)<br />

sage: p.add_constraint(p[0] - 2*p[1], min = 1)<br />

To obtain the list of all constraints:<br />

sage: p.constraints()<br />

# not tested<br />

[(1.0, ([1, 0], [-1.0, 1.0]), 4.0), (1.0, ([2, 0], [-2.0, 1.0]), None)]<br />

Or constraint 0 only:<br />

sage: p.constraints(0)<br />

# not tested<br />

(1.0, ([1, 0], [-1.0, 1.0]), 4.0)<br />

A list of constraints containing only 1:<br />

sage: p.constraints([1]) # not tested<br />

[(1.0, ([2, 0], [-2.0, 1.0]), None)]<br />

TESTS:<br />

As the ordering of the variables in each constraint depends on the solver used, we define a short function<br />

reordering it before it is printed. The output would look the same without this function applied:<br />

16 Chapter 2. Mixed integer linear programming

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

Saved successfully!

Ooh no, something went wrong!