Fichier batch lindo

Résolu
cs_abrouch Messages postés 5 Date d'inscription mercredi 10 novembre 2010 Statut Membre Dernière intervention 13 novembre 2010 - 11 nov. 2010 à 22:54
cs_abrouch Messages postés 5 Date d'inscription mercredi 10 novembre 2010 Statut Membre Dernière intervention 13 novembre 2010 - 13 nov. 2010 à 02:40
bjr;

comment je peux creer un fichier batch pour le solveur lindo et l'exécuter à partir mon application ??

j'ai essayé
MIN Y1 + Y2 + Y3
SUBJECT TO

30 X11 + 10 X21 + 20 X31 - 100 Y1<= 0
30 X12 + 10 X22 + 20 X32 -100 Y2<= 0

30 X13 + 10 X23 + 20 X33 -100 Y3<= 0

X11 + X12 + X13 =1
X21 + X22 + X23 =1
X31 + X32 + X33 =1

END
INTEGER Y1
INTEGER Y2
INTEGER Y3
INTEGER X11
INTEGER X21
INTEGER X31
INTEGER X12
INTEGER X22
INTEGER X32
INTEGER X13
INTEGER X23
INTEGER X33

DIVE ttt.txt

GO
dans un fichier 1.cmd et j'ai fait system("start 1.cmd");mais le probleme c'est la lindo s'execute sans executer le probleme linéraire ecrit dans le batch

Merciiiiiiiiii

6 réponses

cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
12 nov. 2010 à 11:57
Salut,

Heu... Tu as fait system("start 1.cmd"); et ça t'as lancé lindo ???

Enfin bref... Il faut probablement que tu fasses une redirection. Que tu envoies le contenu de ton fichier directement à lindo en somme.

system("lindo < 1.cmd");


J'ai enlever le start. Il ne servirait que si tu ne souhaitais pas attendre la fin de lindo pour continuer l'exécution du programme C.

Comme c'est plutôt du C finalement (C'est un fichier batch, mais pas du tout batch ms-dos), je vais déplacé sur cppfrance.
3
cs_abrouch Messages postés 5 Date d'inscription mercredi 10 novembre 2010 Statut Membre Dernière intervention 13 novembre 2010
12 nov. 2010 à 13:02
Bjr;

j'ai essayer system ("start c:Lindow32.exe 1.cmd" )et non pas system("start N.cmd"),le lindo s'ouvre avec le fichier 1.cmd mais il n'exécute pas ce qui se trouve dedans...enfaite je suis débutante dans les fichier batch et leur manipulation
j'ai ajouté le mot BATCH au début du fichier..mais rien ne se passe
je veux que lindo résout automatiquement mon programme lineaire et renvoie le resulat vers un fichier ttt.txt pour récupérer la valeur objectif sans passer par l'execution manuelle de LINDO....STP aidez moi c urgent je suis bloquée depuis 3 jours ............
0
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
12 nov. 2010 à 18:08
Attention à ne pas utiliser le mot "batch" à tort et à travers.
"batch" se traduit en français par lot.

Mais en informatique, un "fichier batch" est dans 95% des cas un fichier de commandes MS-DOS/invite de commande windows.
start, dir, cd, echo... Sont des exemples de commandes DOS.

C'est un raccourcit contestable, mais la quasi totalité des informaticiens le font. Pour un lot de commandes unix, qui est aussi un batch de commandes, on parle de shell script, ou de bash du nom d'interpréteur shell classique.

Ce que tu as là est bien un "lot de commande", donc bien un "fichier batch" au sens stricte, mais pas de commandes MS-DOS.

Par exemple, , tu es hors sujet. Tu parles de fichier batch lindo sur un thread parlant de batch MS-DOS. Il y a des millions de pages traitant des batch ms-dos, et probablement que quelques centaines traitant des batch lindo.

En résumé :

"fichier batch ms-dos" = "fichier batch ms-dos"
"fichier batch unix" = "fichier batch unix"
"fichier batch lindo" = "fichier batch lindo"

[b]Mais :
"fichier batch" = "fichier batch ms-dos"/b
0
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
12 nov. 2010 à 19:21
A ce sujet, plutôt que d'appeler le fichier 1.cmd (Equivalent de .bat), tu devrais l'appeler 1.ltx ou 1.txt.

Un exemple de code VB est fournit avec la doc de lindo (Qui semble d'ailleurs parfois passablement vielle et obsolète par endroit).

Sub Command1_Click ()

' Sample VB matrix generator for LINDO.  Uses
' the LINDO executable for Windows to perform

' the optimization.
   Dim I, X, Y
' Let the user know we are about to start optimization
   Print "Begin optimization..."
' Eliminate any old work files

   On Error Resume Next
   Kill "C:\LINDO\SHELL\LNDIN.TXT"
   Kill "C:\LINDO\SHELL\LNDOUT.TXT"

   On Error GoTo 0
' Open a LINDO Command file

   Open "C:\LINDO\SHELL\LNDIN.TXT" For Output As #1

' Always a good idea to do a PAGE 0

' first off in LINDO command files
   Print #1, "PAGE 0"
' Send the formulation to the command file

   Print #1, "MAX 20X+30Y"
   Print #1, "ST"
   Print #1, "X<50"
   Print #1, "Y<60"
   Print #1, "X+2Y<120"

   Print #1, "END"

' Suppress the standard solution report

   Print #1, "TERSE"

' Solve the model

   Print #1, "GO"

' Open a file for storing the solution
   Print #1, "DIVERT C:\LINDO\SHELL\LNDOUT.TXT"

' Send the solution to the output file

   Print #1, "CPRI /N P"

' Close output file

   Print #1, "RVRT"

' Quit LINDO

   Print #1, "QUIT"

' Close LINDO command file

   Close #1

' Shell to LINDO, passing the name of the
' command file in the command line.  The 2 
' means run LINDO minimized.

   I = Shell("C:\LINDO\LINDO -t""C:\LINDO\SHELL\LNDIN.TXT""", 2)

' We now need to wait until LINDO creates 

' our input file

   On Error Resume Next
   Do

      Err = 0

' Try to open the solution file printed by
' LINDO
      Open "C:\LINDO\SHELL\LNDOUT.TXT" For Input As #1

' Break out of loop if successful

      If Err = 0 Then Exit Do

' Let other tasks run

      DoEvents

   Loop

   On Error GoTo 0

' Read in the variable values

   Input #1, X, Y

' Close solution file

   Close #1

' Print solution on screen

   Print "X and Y =", X, Y

End Sub


L'important, c'est le -t.
Si tu essais en invite de commande l'équivalent de :
c:\Lindow32.exe -t 1.txt


Lindo devrait derait résoudre le problème (Testé chez moi).
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_abrouch Messages postés 5 Date d'inscription mercredi 10 novembre 2010 Statut Membre Dernière intervention 13 novembre 2010
12 nov. 2010 à 23:28
Bsr;

d'abord Merciiii pour les réponses...mais malheuresement j'ai essayer
c:\Lindow32.exe -t 1.txt(Lindo souvre et il affiche le fichier 1.txt) en invite de commande ça na pas marché et même j'ai mis le chemain du fichier 1 c:\lindow32.exe -t c:\1.txt encore la meme chose.......
STP si tu peux me dire comment je peux traduire ça dans le corps du code C et je veux savoir si t'as changer dans le fichier 1.txt pour avoir une solution.......Bonne soiré
0
cs_abrouch Messages postés 5 Date d'inscription mercredi 10 novembre 2010 Statut Membre Dernière intervention 13 novembre 2010
13 nov. 2010 à 02:40
BSR;
j'ai trouvé un code dans un fichier nommé shell dans un dossier shell aussi sous le c:\ et qui ressemble un peu à ce que tu m'a envoyé ; il est écrit en c mais ce code ne fait que l'affichage et l'écriture dans LND IN.txt
#include <stdio.h> // for file i/o
#include // for dup functions
#include // for spawn function

void main()
{
char *cFileIn = "C:\\LINDO\\LNDIN.TXT";
char *cFileOut = "C:\\LINDO\\LNDOUT.TXT";
char *cFileSolu = "C:\\LINDO\\SOLUTION.TXT";
float fXVal, fYVal;
FILE *fp, *fpIn, *fpOut, *fpSolution;
int nStdIn, nStdOut;

// Open a LINDO script file
fp = fopen( cFileIn, "w");

// Always a good idea to do a PAGE 0 first off in LINDO script files
fprintf( fp, "PAGE 0\n");

// Send the formulation to the script file
fprintf( fp, "MAX 20X+30Y\n");
fprintf( fp, "ST\n");
fprintf( fp, "X<50\n");
fprintf( fp, "Y<60\n");
fprintf( fp, "X+2Y<120\n");
fprintf( fp, "END\n");

// Supress the standard solution report
fprintf( fp, "TERSE\n");

// Solve the model
fprintf( fp, "GO\n");

// Open a file for storing the solution
fprintf( fp, "DIVERT %s\n", cFileSolu);

// Send the solution to the output file
fprintf( fp, "CPRI /N P\n");

// Close output file
fprintf( fp, "RVRT\n");

// Quit LINDO
fprintf( fp, "QUIT\n");

// Close LINDO command file
fclose( fp);

// Redirect standard input to the script file
nStdIn = dup( 0);
fpIn = fopen( cFileIn, "r");
dup2( fileno( fpIn), 0);

// Redirect standard output to a file
nStdOut = dup( 1);
fpOut = fopen( cFileOut, "w");
dup2( fileno( fpOut), 1);

// Run LINDO and process script file.
spawnlp( P_WAIT, "C:\\LINDO\\LINDO.EXE", " ", NULL);

// Flush i/o streams
fflush( stdin);
fflush( stdout);

// Restore standard i/o
dup2( nStdIn, 0);
dup2( nStdOut, 1);

// Close files
fclose( fpIn);
fclose( fpOut);

// Open solution file
fpSolution = fopen( cFileSolu, "rt");

// Display the solution
fscanf( fpSolution, "%f\n%f", &fXVal, &fYVal);
printf("X and Y = %f %f\n", fXVal, fYVal);

// Close solution file
fclose( fpSolution);
}

franchement j'arrive pas à utiliser ce fichier pour shell et fichier text pour resoudre le probleme de lindo
le fichier lNDIN.txt:


PAGE 0
MAX 1X+4Y
ST
X<5
Y<6
X+2Y<12
END
TERSE
GO
DIVERT C:\LINDO\SOLUTION.TXT
RVRT
QUIT


..STP aidez moi ..BN
0
Rejoignez-nous