You are on page 1of 4

01 -- Sage

http://localhost:8080/home/admin/1/print

01
maximize $200 x_0 + 150 x_1 +100 x_2 + 100 x_3$\\ \\
subject to \\$10 x_0 + 5 x_1 \le 1000$\\
$3 x_1+8x_2+2x_3 \le 2000$\\
$2 x_1 + 2 x_2 + 8x_3 \le 3000$\\
$x_1, x_2, x_3, x_4 \ge 0$

print 'RubySage'
RubySage
p=MixedIntegerLinearProgram()
x=p.new_variable(integer=True, nonnegative=True)
p.set_objective(200*x[0]+150*x[1]+100*x[2]+100*x[3])
p.add_constraint(10*x[0]+5*x[1] <= 1000)
p.add_constraint(3*x[1]+8*x[2]+2*x[3] <= 2000)
p.add_constraint(2*x[1]+2*x[2]+8*x[3] <= 3000)
print ' ', p.solve(), '\nx[0] = ', p.get_values(x[0]),
'\nx[1] = ', p.get_values(x[1]),'\nx[2] = ', p.get_values(x[2]),'\nx[3] =
', p.get_values(x[3])
70000.0
x[0] = 0.0
x[1] = 200.0
x[2] = 100.0
x[3] = 300.0
print ''
val = [0, 200, 100, 300]
coef = [200, 150, 100, 100]
sum(val[k]*coef[k] for k in range(0,4))

70000
print ''

print ''

1/2

20160131 10:18

01 -- Sage

http://localhost:8080/home/admin/1/print

2/2

20160131 10:18

02 -- Sage

http://localhost:8080/home/admin/0/print

02
maximize $10 x_0 + 20 x_1 +15 x_2 + 17 x_3 +10 x_4 + 30 x_5$\\ \\
subject to \\$5 x_0 + x_1 +8 x_2 + 9 x_3 + 5 x_4 + 4 x_5 \le 500000$\\
$x_1, x_2, x_3, x_4 = 0,1$

p=MixedIntegerLinearProgram()
x=p.new_variable(binary=True, nonnegative=True)
p.set_objective(10*x[0]+20*x[1]+15*x[2]+17*x[3]+10*x[4]+30*x[5])
p.add_constraint(5000*x[0]+10000*x[1]+8000*x[2]+9000*x[3]+5000*x[4]+40000*x[5]
<= 50000)
print ' ', p.solve(), '\nx[0] = ', p.get_values(x[0]), '\nx[1] = ',
p.get_values(x[1]),'\nx[2] = ', p.get_values(x[2]),'\nx[3] = ',
p.get_values(x[3]),'\nx[4] = ', p.get_values(x[4]),'\nx[5] = ',
p.get_values(x[5])
72.0
x[0] = 1.0
x[1] = 1.0
x[2] = 1.0
x[3] = 1.0
x[4] = 1.0
x[5] = 0.0

1/1

20160131 10:19

You might also like