@@ -61,7 +61,7 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul
6161
6262 MPB. setattribute! (m, MPB. Sense (), MPB. MinSense)
6363
64- MPB. setobjective! (m, 1 , 0.0 , v, [- 1.0 , 0.0 ])
64+ MPB. setobjective! (m, 0.0 , v, [- 1.0 , 0.0 ])
6565
6666 # TODO : query objective
6767 # (b, a_varref, a_coef, qi, qj, qc) = MPB.getobjective(m)
@@ -82,29 +82,31 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul
8282
8383 test_result (m, v, c, MPB. Success, MPB. FeasiblePoint, MPB. FeasiblePoint, 1 , [1.0 , 0.0 ], [0.0 , - 1.0 ], [0.0 , 0.0 ], [1.0 ], [1.0 ])
8484
85+ end
86+ end
87+ end
88+ """
8589 # add new variable to get:
8690 # max x + 2z
8791 # s.t. x + y + z <= 1
8892 # x,y,z >= 0
89- z = MPB. addvariable! (m, c, [1 ])
90- MPB. setattribute! (m, MPB. VariableLowerBound (), z, 0 )
91- MPB. modifyobjective! (m, z, 2 )
93+ addvar!(m, [1], [1.0], 0, Inf, 2.0)
9294
93- @test MPB . getattribute (m, MPB . VariableCount () ) == 3
94- @test MPB . getattribute (m, MPB . ConstraintCount () ) == 1
95+ @test numvar(m ) == 3
96+ @test numconstr(m ) == 1
9597
9698 optimize!(m)
9799
98- test_result (m, v, c, MPB. Success, MPB. FeasiblePoint, MPB. FeasiblePoint, 2 , [0.0 , 0.0 , 1.0 ], [- 1.0 , - 2.0 , 0.0 ], [0.0 , 0.0 , 0.0 ], [1.0 ], [2.0 ])
99-
100- MPB. setattribute! (m, MPB. VariableLowerBound (), v[1 ], - 1 )
100+ @test status(m) == :Optimal
101+ @test isapprox(getobjval(m), 2, atol=eps)
102+ @test isapprox(norm(getsolution(m) - [0.0, 0.0, 1.0]), 0.0, atol=eps)
103+ @test isapprox(getconstrsolution(m)[1], 1.0, atol=eps)
104+ @test isapprox(getconstrduals(m)[1], 2.0, atol=eps)
105+ @test isapprox(norm(getreducedcosts(m) - [-1.0, -2.0, 0.0]), 0.0, atol=eps)
101106
107+ setvarLB!(m, [-1.0,0.0,0.0])
102108 optimize!(m)
103109
104- end
105- end
106- end
107- """
108110 @test status(m) == :Optimal
109111 @test isapprox(getobjval(m), 3, atol=eps)
110112
@@ -143,35 +145,53 @@ end
143145 @test isapprox(norm(getreducedcosts(m) - [0.0, 0.0, -1.5]), 0.0, atol=eps)
144146 end
145147
148+ """
146149
150+ function linprogsolvertest2 (solver:: AbstractMathProgSolver , eps = Base. rtoldefault (Float64))
151+ @testset " Testing LP interface with $solver part 2" begin
147152 @testset " addvar! interface" begin
148153 m = LinearQuadraticModel (solver)
149154
150155 # Min -x
151156 # s.t. x + y <= 1
152157 # x, y >= 0
153- addvar!(m, 0, Inf, -1)
154- addvar!(m, 0, Inf, 0)
155- addconstr!(m, [1, 2], [1.0, 1.0], -Inf, 1.0)
156- @test numvar(m) == 2
157- @test numconstr(m) == 1
158- @test getvarLB(m) == [0.,0.]
159- @test getvarUB(m)[1] >= 1e20
160- @test getvarUB(m)[2] >= 1e20
161- @test getconstrLB(m)[1] <= -1e20
162- @test getconstrUB(m)[1] == 1.0
163- @test getobj(m) == [-1.,0.]
164- @test getsense(m) == :Min
158+ m = MPB. Model (solver)
159+
160+ x = MPB. addvariable! (m)
161+ y = MPB. addvariable! (m)
162+
163+ MPB. setattribute! (m, MPB. VariableLowerBound (), [x, y], [0 , 0 ])
164+
165+ c = MPB. addconstraint! (m, - 1 , [x, y], [1.0 , 1.0 ], MPB. NonPositive (1 ))
166+
167+ MPB. setattribute! (m, MPB. Sense (), MPB. MinSense)
168+ MPB. setobjective! (m, 0.0 , x, - 1.0 )
169+
170+ @test MPB. getattribute (m, MPB. VariableCount ()) == 2
171+ @test MPB. getattribute (m, MPB. ConstraintCount ()) == 1
172+
173+ # getters #190
174+ # @test getvarLB(m) == [0.,0.]
175+ # @test getvarUB(m)[1] >= 1e20
176+ # @test getvarUB(m)[2] >= 1e20
177+ # @test getconstrLB(m)[1] <= -1e20
178+ # @test getconstrUB(m)[1] == 1.0
179+ # @test getobj(m) == [-1.,0.]
180+ # @test getsense(m) == :Min
165181
166182 optimize! (m)
167- @test status(m) == :Optimal
168- @test isapprox(getobjval(m), -1, atol=eps)
169- @test isapprox(norm(getsolution(m) - [1.0, 0.0]), 0.0, atol=eps)
170- @test isapprox(getconstrsolution(m)[1], 1.0, atol=eps)
171- @test isapprox(getconstrduals(m)[1], -1.0, atol=eps)
172- @test isapprox(norm(getreducedcosts(m) - [0.0, 1.0]), 0.0, atol=eps)
173- end
183+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
184+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
185+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
186+
187+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), - 1.0 , atol= eps)
188+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), [x, y]), [1.0 , 0.0 ], atol= eps)
189+
190+ @test isapprox (MPB. getattribute (m, MPB. ConstraintPrimal ()), 0.0 , atol= eps)
174191
192+ @test isapprox (MPB. getattribute (m, MPB. ConstraintDual ()), - 1.0 , atol= eps)
193+ @test isapprox (MPB. getattribute (m, MPB. VariableDual (), [x, y]), [0.0 , 1.0 ], atol= eps)
194+ end
175195
176196 @testset " setconstrLB! and setconstrUB!" begin
177197 # ###################################
@@ -182,67 +202,100 @@ end
182202 # Setting upper and lower bound to same value works
183203 #
184204
185- m = LinearQuadraticModel(solver)
205+ m = MPB. Model (solver)
206+
207+ x = MPB. addvariable! (m)
208+ y = MPB. addvariable! (m)
209+
186210 # Min x - y
187- # s.t. 0.0 <= x
188- # y <= 0.0
211+ # s.t. 0.0 <= x (c1)
212+ # y <= 0.0 (c2)
189213 # x,y unbounded
214+ c1 = MPB. addconstraint! (m, 0.0 , x, [1.0 , 0.0 ], MPB. NonNegative (1 ))
215+ c2 = MPB. addconstraint! (m, 0.0 , y, [0.0 , 1.0 ], MPB. NonPositive (1 ))
216+
217+ MPB. setattribute! (m, MPB. Sense (), MPB. MinSense)
190218
191- loadproblem !(m, [ 1.0 0.0 ; 0.0 1.0 ] , [-Inf, -Inf ], [Inf,Inf], [ 1.0, -1.0], [0.0,-Inf], [Inf,0.0], :Min )
219+ MPB . setobjective ! (m, 0.0 , [x, y ], [1.0 , - 1.0 ])
192220
193- optimize!(m)
221+ MPB . optimize! (m)
194222
195- @test status(m) == :Optimal
196- @test isapprox(getobjval(m), 0.0, atol=eps)
197- @test isapprox(norm(getsolution(m)), 0.0, atol=eps)
223+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
224+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
225+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
226+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 0.0 , atol= eps)
227+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), [x, y]), [0.0 , 0.0 ], atol= eps)
198228
199229 # Min x - y
200- # s.t. 100.0 <= x
230+ # s.t. 100.0 <= x or -100 + x \in NonNegative
201231 # y <= 0.0
202232 # x,y unbounded
203- setconstrLB !(m,[ 100.0,-Inf] )
233+ modifyconstraint ! (m, c1, 1 , - 100.0 )
204234 optimize! (m)
205- @test status(m) == :Optimal
206- @test isapprox(getobjval(m), 100.0, atol=eps)
207- @test isapprox(norm(getsolution(m) - [ 100.0, 0.0 ]), 0.0, atol=eps)
235+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
236+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
237+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
238+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 100.0 , atol= eps)
239+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), [x, y]), [100.0 , 0.0 ], atol= eps)
208240
209241 # Min x - y
210242 # s.t. 100.0 <= x
211243 # y <= -100.0
212244 # x,y unbounded
213- setconstrUB !(m,[Inf,- 100.0] )
245+ modifyconstraint ! (m, c2, 1 , 100.0 )
214246 optimize! (m)
215- @test status(m) == :Optimal
216- @test isapprox(getobjval(m), 200.0, atol=eps)
217- @test isapprox(norm(getsolution(m) - [ 100.0, -100.0 ]), 0.0, atol=eps)
247+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
248+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
249+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
250+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 200.0 , atol= eps)
251+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), [x, y]), [100.0 , - 100.0 ], atol= eps)
218252 end
219253
220254 @testset " Issue #40 from Gurobi.jl" begin
221255 # Test issue #40 from Gurobi.jl
222256 # min x
223- # s.t. x >= 0
224- # x >= 3
225- m = LinearQuadraticModel(solver)
226- loadproblem!(m, [1.0 1.0]', [-Inf], [Inf], [1.0], [0.0, 3.0], [Inf, Inf], :Min)
227- optimize!(m)
228- for i = 1:length(getconstrLB(m))
229- @test getconstrLB(m)[i] <= getconstrsolution(m)[i] + eps
230- @test getconstrsolution(m)[i] <= getconstrUB(m)[i] + eps
257+ # s.t. x >= 0 (c1)
258+ # x >= 3 (c2)
259+
260+ m = MPB. Model (solver)
261+
262+ x = MPB. addvariable! (m)
263+
264+ c = MPB. addconstraint! (m, [0.0 - 3.0 ], [x x], [1.0 1.0 ], MPB. NonNegative (2 ))
265+
266+ MPB. setattribute! (m, MPB. Sense (), MPB. MinSense)
267+
268+ MPB. setobjective! (m, 0.0 , [x], [1.0 ])
269+
270+ MPB. optimize! (m)
271+
272+ for i = 1 : MPB. getattribute (m, MPB. ConstraintCount ())
273+ # Get Bounds #190
274+ # @test getconstrLB(m)[i] <= getconstrsolution(m)[i] + eps
275+ # @test getconstrsolution(m)[i] <= getconstrUB(m)[i] + eps
231276 end
232277
233278 # min x
234279 # s.t. x <= 0
235280 # x <= 3
236- m = LinearQuadraticModel(solver)
237- loadproblem!(m, [1.0 1.0]', [-Inf], [Inf], [1.0], [-Inf, -Inf], [0.0, 3.0], :Max)
238- optimize!(m)
239- for i = 1:length(getconstrLB(m))
240- @test getconstrLB(m)[i] <= getconstrsolution(m)[i] + eps
241- @test getconstrsolution(m)[i] <= getconstrUB(m)[i] + eps
281+ m = MPB. Model (solver)
282+
283+ x = MPB. addvariable! (m)
284+
285+ c = MPB. addconstraint! (m, [0.0 - 3.0 ], [x x], [1.0 1.0 ], MPB. NonPositive (2 ))
286+
287+ MPB. setattribute! (m, MPB. Sense (), MPB. MinSense)
288+
289+ MPB. setobjective! (m, 0.0 , [x], [1.0 ])
290+
291+ MPB. optimize! (m)
292+ for i = 1 : MPB. getattribute (m, MPB. ConstraintCount ())
293+ # Get Bounds #190
294+ # @test getconstrLB(m)[i] <= getconstrsolution(m)[i] + eps
295+ # @test getconstrsolution(m)[i] <= getconstrUB(m)[i] + eps
242296 end
243297 end
244298
245-
246299 @testset " Change coeffs, del constr, del var" begin
247300 # ####################################
248301 # Start from simple LP
@@ -254,29 +307,48 @@ end
254307
255308 # maximize x + y
256309 #
257- # s.t. 2 x + 1 y <= 4
258- # 1 x + 2 y <= 4
310+ # s.t. 2 x + 1 y <= 4 (c1)
311+ # 1 x + 2 y <= 4 (c2)
259312 # x >= 0, y >= 0
260313 #
261314 # solution: x = 1.3333333, y = 1.3333333, objv = 2.66666666
262315
263- m = LinearQuadraticModel (solver)
316+ m = MPB . Model (solver)
264317
265- loadproblem!(m, [ 2.0 1.0 ; 1.0 2.0 ], [0.0,0.0], [Inf,Inf], [1.0, 1.0], [-Inf, -Inf], [4.0,4.0], :Max)
318+ v = MPB. addvariables! (m, 2 )
319+
320+ MPB. setattribute! (m, MPB. VariableLowerBound (), v, [0 , 0 ])
266321
267- optimize!(m)
268- @test status(m) == :Optimal
269- @test isapprox(getobjval(m), 2.6666666666, atol=eps)
270- @test isapprox(norm(getsolution(m) - [1.3333333333, 1.3333333333]), 0.0, atol=eps)
322+ c1 = MPB. addconstraint! (m, - 4 , v, [2 , 1 ], MPB. NonPositive (1 ))
323+ c2 = MPB. addconstraint! (m, - 4 , v, [1 , 2 ], MPB. NonPositive (1 ))
271324
272- # copy and solve again
325+ MPB. setattribute! (m, MPB. Sense (), MPB. MaxSense)
326+
327+ MPB. setobjective! (m, 0.0 , v, [1.0 , 1.0 ])
328+
329+ MPB. optimize! (m)
330+
331+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
332+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
333+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
273334
274- if applicable(copy, m)
335+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 2.6666666666 , atol= eps)
336+
337+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), v), [1.3333333333 , 1.3333333333 ], atol= eps)
338+
339+ # copy and solve again
340+
341+ if applicable (copy, m) # see 188
275342 m2 = copy (m)
343+
276344 optimize! (m2)
277- @test status(m2) == :Optimal
278- @test isapprox(getobjval(m2), 2.6666666666, atol=eps)
279- @test isapprox(norm(getsolution(m2) - [1.3333333333, 1.3333333333]), 0.0, atol=eps)
345+
346+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
347+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
348+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
349+
350+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 2.6666666666 , atol= eps)
351+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), v), [1.3333333333 , 1.3333333333 ], atol= eps)
280352 end
281353
282354
@@ -289,11 +361,18 @@ end
289361 #
290362 # solution: x = 0, y = 2, objv = 2
291363 if applicable (changecoeffs!, m, [1 ], [2 ], [2. ])
292- changecoeffs !(m, [1], [2], [2.] )
364+ modifyconstraint ! (m, c1, v [2 ], 2.0 )
293365 optimize! (m)
294- @test status(m) == :Optimal
295- @test isapprox(getobjval(m), 2.0, atol=eps)
296- @test isapprox(norm(getsolution(m) - [0.0, 2.0]), 0.0, atol=eps)
366+
367+ MPB. optimize! (m)
368+
369+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
370+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
371+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
372+
373+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 2.0 , atol= eps)
374+
375+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), v), [0.0 , 2.0 ], atol= eps)
297376 end
298377
299378
@@ -304,12 +383,18 @@ end
304383 # x >= 0, y >= 0
305384 #
306385 # solution: x = 4, y = 0, objv = 4
307- if applicable(delconstrs!, m, [1])
308- delconstrs!(m, [1])
386+ if applicable (delete!, m, [1 ])
387+ delete! (m, c1)
388+
309389 optimize! (m)
310- @test status(m) == :Optimal
311- @test isapprox(getobjval(m), 4.0, atol=eps)
312- @test isapprox(norm(getsolution(m) - [4.0, 0.0]), 0.0, atol=eps)
390+
391+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
392+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
393+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
394+
395+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 4.0 , atol= eps)
396+
397+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), v), [4.0 , 0.0 ], atol= eps)
313398 end
314399
315400 # delvars and solve
@@ -319,18 +404,24 @@ end
319404 # y >= 0
320405 #
321406 # solution: y = 2, objv = 2
322- if applicable(delvars!, m, [1])
323- delvars!(m, [1])
407+ if applicable (delete!, m, [1 ])
408+ delete! (m, v[1 ])
409+
324410 optimize! (m)
325- @test status(m) == :Optimal
326- @test isapprox(getobjval(m), 2.0, atol=eps)
327- @test isapprox(getsolution(m)[1], 2.0, atol=eps)
411+
412+ @test MPB. getattribute (m, MPB. TerminationStatus ()) == :Success
413+ @test MPB. getattribute (m, MPB. PrimalStatus ()) == MPB. FeasiblePoint
414+ @test MPB. getattribute (m, MPB. DualStatus ()) == MPB. FeasiblePoint
415+
416+ @test isapprox (MPB. getattribute (m, MPB. ObjectiveValue ()), 2.0 , atol= eps)
417+
418+ @test isapprox (MPB. getattribute (m, MPB. VariablePrimal (), v[2 ]), 2.0 , atol= eps)
328419 end
329420 end
330421 end
331422end
332423
333-
424+ """
334425
335426function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtoldefault(Float64))
336427 @testset "Testing LP interface extra with $solver " begin
0 commit comments