FIXED: library(simplex): Correctly drive remaining artificial        variables out of the basis after phase 1. Mihai Fonoage.
FIXED: library(simplex): Correctly drive remaining artificial
       variables out of the basis after phase 1. Mihai Fonoage.

Feasibility of constraints tested with:

   :- use_module(library(simplex)).

   rows(_)  --> [].
   rows(Vs) --> [C],
           { maplist(left, Vs, Left), linrel(Rel), coeff(Right),
             C =.. [Rel,Left,Right] },
           rows(Vs).

   left(V, C*V) :- coeff(C).

   coeff(C) :- between(-2, 2, C).

   linrel(=).
   linrel(=<).
   linrel(>=).

   variables([], _).
   variables([x(N0)|Vs], N0) :- N1 is N0 + 1, variables(Vs, N1).

   run :-
           length(Vs, L),
           portray_clause(L),
           variables(Vs, 1),
           between(1, L, LCs),
           length(Cs, LCs),
           phrase(rows(Vs), Cs),
           gen_state(S0),
           post_constraints(Cs, S0, S1),
           maplist(left, Vs, Obj),
           (   minimize(Obj, S1, S), maplist(satisfied(S,Cs), Cs)
           ;   maximize(Obj, S1, S), maplist(satisfied(S,Cs), Cs)
           ),
           false.

   satisfied(S, Cs, C) :-
           C =.. [Rel, Left, Right],
           left_value(Left, S, 0, V),
           Goal =.. [Rel,V,Right],
           (   Goal -> true
           ;   portray_clause(failed-Cs-C-S), halt
           ).

   left_value([], _, V, V).
   left_value([C*Var|CVs], S, V0, V) :-
           variable_value(S, Var, Val),
           V1 is V0 + C*Val,
           left_value(CVs, S, V1, V).

   post_constraints([]) --> [].
   post_constraints([C|Cs]) --> constraint(C), post_constraints(Cs).

Previously:

   ?- run.
   %@ 0.
   %@ 1.
   %@ 2.
   %@ failed-[[-2*x(1), -2*x(2)]=0, [-2*x(1), 1*x(2)]=<1]- ([-2*x(1), -2*x(2)]=0)-solved(tableau(row(z, [1, 0, 0, 0], 1), [0, 1, x(1), x(2)], [1, 0, 1, 1], [row(x(2), [1, 0, -2, 1], 1)]), [[0, 1], [0, 0]], []).

Now:

   ?- run.
   %@ 0.
   %@ 1.
   %@ 2.
   %@ 3.

edechter/swipl-devel,mndrix/swipl-devel,mndrix/swipl-devel,mndrix/swipl-devel,jn7163/swipl-devel,jn7163/swipl-devel,jn7163/swipl-devel,mndrix/swipl-devel,edechter/swipl-devel,mndrix/swipl-devel,edechter/swipl-devel,koryonik/swipl-devel,jn7163/swipl-devel,koryonik/swipl-devel,koryonik/swipl-devel,koryonik/swipl-devel,edechter/swipl-devel,edechter/swipl-devel,jn7163/swipl-devel,koryonik/swipl-devel