thnx i got it working.
Am 30.07.2010 12:00, schrieb Harald Schilly: > On 30 Jul., 00:01, Johannes <dajo.m...@web.de> wrote: > >> Hi list, >> i try to solve a linear equation in ZZ in the variables w_i: >> > Here is a MILP formulation of your problem, I've pasted the input cell > in {{{}}} and the output in between > > {{{ > p = MixedIntegerLinearProgram(maximization=False) > # not reals, we want integers > w = p.new_variable(integer=True) > p.add_constraint(w[0] + w[1] + w[2] - 14*w[3] == 0) > p.add_constraint(w[1] + 2*w[2] - 8*w[3] == 0) > p.add_constraint(2*w[2] - 3*w[3] == 0) > # we don't want the trivial solution > p.add_constraint(w[3] >= 1) > # minimum of each variable is 0 by default, make it +infinity > [p.set_min(w[i], None) for i in range(1,4) ] > # minimize w3 > p.set_objective(w[3]) > # show what we have created so far > p.show() > }}} > > > Minimization: > x_3 > Constraints: > 0 <= x_0 +x_1 +x_2 -14 x_3 <= 0 > 0 <= x_1 +2 x_2 -8 x_3 <= 0 > 0 <= 2 x_2 -3 x_3 <= 0 > -1 x_3 <= -1 > Variables: > x_0 is an integer variable (min=0.0, max=+oo) > x_1 is an integer variable (min=-oo, max=+oo) > x_2 is an integer variable (min=-oo, max=+oo) > x_3 is an integer variable (min=-oo, max=+oo) > > {{{ > # solve it (default is GLPK, there are other solvers, too) > print 'Objective Value:', p.solve() > }}} > > Objective Value: 2.0 > > {{{ > p.get_values(w) > }}} > > {0: 15.0, 1: 10.0, 2: 3.0, 3: 2.0} > > {{{ > # to get one value as integer > w_sol = p.get_values(w) > int(round(w_sol[2])) > }}} > > 3 > > > greetings H > > -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org