IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Discussion :

probleme avec le simplex


Sujet :

Windows

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Août 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 4
    Points : 1
    Points
    1
    Par défaut probleme avec le simplex
    bonjour à tous,

    j'ai un probleme avec le simplex, les résultats sont erronés, et je n'arrive pas à détecter l'erreur, est ce q qlq peut m'aider, svp, c urgent !

    merci

  2. #2
    Rédacteur

    Avatar de ram-0000
    Homme Profil pro
    Consultant en sécurité
    Inscrit en
    Mai 2007
    Messages
    11 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en sécurité
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2007
    Messages : 11 517
    Points : 50 367
    Points
    50 367
    Par défaut
    Bien sûr, montre nous ton code et explique nous ton problème

    Raymond
    Vous souhaitez participer à la rubrique Réseaux ? Contactez-moi

    Cafuro Cafuro est un outil SNMP dont le but est d'aider les administrateurs système et réseau à configurer leurs équipements SNMP réseau.
    e-verbe Un logiciel de conjugaison des verbes de la langue française.

    Ma page personnelle sur DVP
    .

  3. #3
    Nouveau Candidat au Club
    Inscrit en
    Août 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    merci ram,

    bon, j'utilise le delphi, et le programme du simplex est dans un module séparé, les procedures du programme sont :



    Procedure Data; // remplissage du tableau initial
    Var R1,R2: real;

    I,J: Integer;
    Begin

    XERR := 0;
    nv := nbVar;
    nc := nbCtr+nbVar;
    setlength(ts,nc+2,nv+2);
    setlength(tabvar,nbvar);

    for i := 0 to nc+1 do
    for j := 0 to nv+1 do
    ts[i,j] := 0;

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

    // writeln(' CONSTRAINT X', I);
    FOR J := 1 TO NV DO
    begin
    R2 := A[i-1,j-1];
    TS[I + 1, J + 1] := -R2 ;
    end;
    //write(' Right hand side ? '); readln(TS[I + 1, 1])
    TS[I + 1, 1] := B[0];
    end;

    for i := nc-nv+2 to nc+1 do
    begin
    ts[i,i-nc+nv] := -1;
    ts[i,1] := dom5;
    end;

    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;

    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
    begin
    V := ABS(TS[I, 1] / TS[I, P2]);
    IF V < RAP THEN
    begin
    RAP := V;
    P1 := I
    end;
    end;
    end;
    V := TS[0, P2]; TS[0, P2] := TS[P1, 0]; TS[P1, 0] := V
    End;


    Procedure FORMULA;{******************************************************************************}
    Var I,J: Integer;
    Begin
    FOR I := 1 TO NC + 1 DO
    begin
    IF I <> P1 THEN // ligne non pivot
    FOR J := 1 TO NV + 1 DO
    begin
    IF J <> P2 THEN // colonne non pivot
    TS[I, J] := TS[I, J] - TS[P1, J] * TS[I, P2] / TS[P1, P2];
    end;
    end;
    TS[P1, P2] := 1.0 / TS[P1, P2];
    FOR J := 1 TO NV + 1 DO
    begin
    IF J <> P2 THEN
    TS[P1, J] := TS[P1, J] * ABS(TS[P1, P2]);
    end;
    FOR I := 1 TO NC + 1 DO
    begin
    IF I <> P1 THEN
    TS[I, P2] := TS[I, P2] * TS[P1, P2];
    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 = 0 THEN
    FOR J := 2 TO NV + 1 DO
    IF TS[1, J] > 0 THEN NOPTIMAL := 1;
    End;

    Procedure RESULTS;{********************************************************************************}
    Label 30,70,100;
    Var I,J: Integer;
    Begin
    IF XERR = 0 THEN GOTO 30;
    // writeln(' NO SOLUTION.');
    GOTO 100;
    30:
    if xerr = 0 then
    begin
    for i := 0 to nbvar-1 do
    tabvar[i] := 0;

    FOR I := 1 TO NV DO
    FOR J := 2 TO NC + 1 DO
    begin
    IF TS[J, 0] = I THEN
    begin
    form5.Memo3.Lines.Add('X'+inttostr(I)+' = '+floattostr(TS[J, 1])+', ');
    // writeln;
    // writeln(' VARIABLE X', I,': ', TS[J, 1]:8:2);
    tabvar[i-1] := TS[J, 1];
    end;
    70: end;
    // writeln;
    form5.Memo3.Lines.Add('Z = '+floattostr(TS[1, 1]));
    // writeln(' ECONOMIC FUNCTION: ', TS[1, 1]:8:2);
    100://writeln; writeln
    end;
    End;

    mon pb est q ce programme marche bien avec qlq instances, mais il donne des résultats erronés avec d'autres,

  4. #4
    Nouveau Candidat au Club
    Inscrit en
    Août 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    j'ai copié ce code pascal de l'internet, et je l'ai modifié.
    j'ai l'impression que ce programme ne marche qu'avec les systèmes linéaires tels que les les constantes (partie droite des contraintes) des contraintes sont positifs.

  5. #5
    Nouveau Candidat au Club
    Inscrit en
    Août 2010
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    le code pascal original est le suivant :


    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}



    je veux savoir est ce que ce programme est correct ?

Discussions similaires

  1. Probleme avec la copie des surfaces
    Par Black_Daimond dans le forum DirectX
    Réponses: 3
    Dernier message: 09/01/2003, 10h33
  2. Problèmes avec le filtrage des ip
    Par berry dans le forum Réseau
    Réponses: 9
    Dernier message: 30/12/2002, 07h51
  3. probleme avec la touche F10
    Par b.grellee dans le forum Langage
    Réponses: 2
    Dernier message: 15/09/2002, 22h04
  4. Probleme avec fseek
    Par Bjorn dans le forum C
    Réponses: 5
    Dernier message: 04/08/2002, 07h17
  5. [Kylix] probleme avec un imagelist
    Par NicoLinux dans le forum EDI
    Réponses: 4
    Dernier message: 08/06/2002, 23h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo