# Ticket #7012: trac_7012-details.patch

File trac_7012-details.patch, 1.5 KB (added by ncohen, 11 years ago)
• ## sage/numerical/knapsack.py

```# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1254669768 -7200
# Node ID 14516cf5b0ccefed648d0043a7c9beb7121a5598
# Parent  03eaf3619a9cd4f998c1611f2d2037c7f60c88b8
knapsack updated, one doctest fixed

diff -r 03eaf3619a9c -r 14516cf5b0cc sage/numerical/knapsack.py```
 a seq = [(x,1) for x in seq] from sage.numerical.mip import MixedIntegerLinearProgram p = MixedIntegerLinearProgram(sense=1) p = MixedIntegerLinearProgram(maximization=True) present = p.new_variable() p.set_objective(sum([present[i] * seq[i][1] for i in range(len(seq))])) p.add_constraint(sum([present[i] * seq[i][0] for i in range(len(seq))]), max=max)
• ## sage/numerical/mip.pyx

`diff -r 03eaf3619a9c -r 14516cf5b0cc sage/numerical/mip.pyx`
 a sage: p.add_constraint(1.5*x[1] + 3*x[2], max=4) sage: p.solve()           # optional - requires Glpk or COIN-OR/CBC 6.6666666666666661 sage: p.get_values(x)     # optional - requires Glpk or COIN-OR/CBC sage: p.get_values(x)     # optional random - requires Glpk or COIN-OR/CBC {1: 0.0, 2: 1.3333333333333333} sage: ### Computation of a maximum stable set in Petersen's graph