Code simplex

Résolu/Fermé
oundou Messages postés 12 Date d'inscription samedi 22 mai 2010 Statut Membre Dernière intervention 16 novembre 2011 - 7 août 2010 à 23:35
oundou Messages postés 12 Date d'inscription samedi 22 mai 2010 Statut Membre Dernière intervention 16 novembre 2011 - 9 août 2010 à 14:03
bonjour à tous,

voici un code du programme simplex, est c q ce programme est correct ?

PROGRAM SIMPLEX;
Uses Crt;

Const
CMAX = 10; {max. number of variables in economic function}
VMAX = 10; {max. number of constraints}

Var
NC, NV, NOPTIMAL,P1,P2,XERR: Integer;
TS: Array[0..CMAX,0..VMAX] of real;

{introduction des données****************************************************************}

Procedure Data;
Var R1,R2: real;

I,J: Integer;
Begin
writeln;
writeln(' LINEAR PROGRAMMING');
writeln;


write(' NUMBER OF VARIABLES OF ECONOMIC FUNCTION ? '); readln(NV);
writeln;
write(' NUMBER OF CONSTRAINTS ? '); readln(NC);
writeln;

R1 := 1;

writeln(' INPUT COEFFICIENTS OF ECONOMIC FUNCTION:');
FOR J := 1 TO NV DO
begin
write(' X',J,' ? '); readln(R2);
TS[1, J + 1] := R2 * R1
end;
write(' Right hand side ? '); readln(R2);
TS[1, 1] := R2 * R1;
FOR I := 1 TO NC DO
begin
writeln;
writeln(' CONSTRAINT X', I);
FOR J := 1 TO NV DO
begin
write(' X',J,' ? '); readln(R2);
TS[I + 1, J + 1] := -R2
end;
write(' Right hand side ? '); readln(TS[I + 1, 1])
end;
writeln;
writeln(' RESULTS:');
writeln;
FOR J := 1 TO NV DO TS[0, J + 1] := J;
FOR I := NV + 1 TO NV + NC DO TS[I - NV + 1, 0] := I;

End;

Procedure Pivot; Forward;
Procedure Formula; Forward;
Procedure Optimize; Forward;
Procedure ecriture; Forward;

{procedure principale du simplexe *****************************************************************}
Procedure SIMPLEX1;
Label 10;
Begin
10: PIVOT;
FORMULA;
OPTIMIZE;
IF NOPTIMAL = 1 THEN GOTO 10
End;

{pivot ********************************************************************************************}
Procedure PIVOT;
Label 100;
Var RAP,V,XMAX: real;
I,J: Integer;
Begin
XMAX := 0.0;
FOR J := 2 TO NV + 1 DO
begin
IF (TS[1, J] > 0) AND (TS[1, J] > XMAX) THEN
begin
XMAX := TS[1, J];
P2 := J
end
end;
RAP := 999999.0;
FOR I := 2 TO NC + 1 DO
begin
IF TS[I, P2] >= 0 THEN GOTO 100;
V := ABS(TS[I, 1] / TS[I, P2]);
IF V < RAP THEN
begin
RAP := V;
P1 := I
end;
100: end;
V := TS[0, P2]; TS[0, P2] := TS[P1, 0]; TS[P1, 0] := V
End;


Procedure FORMULA;{******************************************************************************}
Label 60,70,100,110;
Var I,J: Integer;
Begin
FOR I := 1 TO NC + 1 DO
begin
IF I = P1 THEN GOTO 70;
FOR J := 1 TO NV + 1 DO
begin
IF J = P2 THEN GOTO 60;
TS[I, J] := TS[I, J] - TS[P1, J] * TS[I, P2] / TS[P1, P2];
60: end;
70: end;
TS[P1, P2] := 1.0 / TS[P1, P2];
FOR J := 1 TO NV + 1 DO
begin
IF J = P2 THEN GOTO 100;
TS[P1, J] := TS[P1, J] * ABS(TS[P1, P2]);
100: end;
FOR I := 1 TO NC + 1 DO
begin
IF I = P1 THEN GOTO 110;
TS[I, P2] := TS[I, P2] * TS[P1, P2];
110: end
End;

Procedure OPTIMIZE;{*******************************************************************************}
Label 10;
Var I,J: Integer;
Begin
FOR I := 2 TO NC + 1 DO
IF TS[I, 1] < 0 THEN XERR := 1;
NOPTIMAL := 0;
IF XERR = 1 THEN GOTO 10;
FOR J := 2 TO NV + 1 DO
IF TS[1, J] > 0 THEN NOPTIMAL := 1;
10: End;

Procedure RESULTS;{********************************************************************************}
Label 30,70,100;
Var I,J: Integer;
Begin
IF XERR = 0 THEN GOTO 30;
writeln(' NO SOLUTION.'); GOTO 100;
30: FOR I := 1 TO NV DO
FOR J := 2 TO NC + 1 DO
begin
IF TS[J, 0] <> I THEN GOTO 70;

writeln;
writeln(' VARIABLE X', I,': ', TS[J, 1]:8:2);

70: end;
writeln;
writeln(' ECONOMIC FUNCTION: ', TS[1, 1]:8:2);
100:writeln; writeln
End;

procedure ecriture;{Affichage d'une matrice de N lignes et P colonnes *****************************}
var I, J : integer ;
begin
writeln('tab ');
for I := 1 to Nv+1 do
begin
for J := 1 to nc+1 do

write (' ',TS[I, J]:8:2,' ' );
writeln { passage à la ligne}

end
end ;








{main program}

BEGIN

Data;
ecriture;
Simplex1;
ecriture;
Results;
ReadKey;

END.

{end of file simplex.pas}

merci

A voir également:

3 réponses

oundou Messages postés 12 Date d'inscription samedi 22 mai 2010 Statut Membre Dernière intervention 16 novembre 2011 1
8 août 2010 à 10:08
c'est une méthode de recherche opérationnelle utilisée pour résoudre les systèmes linéaires avec fonction économique (fct objectif).
1
tarek_dotzero Messages postés 817 Date d'inscription jeudi 19 juillet 2007 Statut Membre Dernière intervention 12 avril 2022 122
8 août 2010 à 02:05
Est ce que vous pouvez me rappller c'est quoi le simplex :d
0
oundou Messages postés 12 Date d'inscription samedi 22 mai 2010 Statut Membre Dernière intervention 16 novembre 2011 1
9 août 2010 à 14:03
enfin, oui ce code est correct.
0