1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| unit fformul;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, ValEdit, ComCtrls;
type
Tformul = class(TForm)
ScrollBox1: TScrollBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
BitBtn1: TBitBtn;
BitBtn3: TBitBtn;
Label4: TLabel;
StringGrid1: TStringGrid;
Label5: TLabel;
StringGrid2: TStringGrid;
ScrollBox2: TScrollBox;
Memo1: TMemo;
procedure BitBtn1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
formul: Tformul;
sommet,arc,nflux,i,j:integer;
f1,f2,f3,f4,f5,f6,f7,f8,f9,f10:array of real;
implementation
{$R *.dfm}
procedure Tformul.BitBtn1Click(Sender: TObject);
var i,j,k,ligne_memo:integer;
equation:string;
begin
label4.Visible:=true;
label5.visible:=true;
stringgrid1.Visible:=true;
stringgrid2.Visible:=true;
sommet:=strtoint(edit1.Text);
arc:=strtoint(edit2.Text);
nflux:=strtoint(edit3.Text);
// matrice incidence sommet arc
stringgrid1.ColCount:=arc+1;
stringgrid1.rowcount:=sommet+1;
for i:=1 to sommet do stringgrid1.Cells[0,i]:=chr(64+i);
for i:=1 to arc do stringgrid1.Cells[i,0]:=inttostr(i);
//capacité de chaque arc
stringgrid2.ColCount:=2;
stringgrid2.rowcount:=arc+1;
for i:=1 to arc do stringgrid2.Cells[0,i]:=inttostr(i);
// flux
For i:=formul.Scrollbox2.ComponentCount-1 DownTo 0 Do formul.Scrollbox2.Components[i].Free;
for i:=1 to nflux do
With Tstringgrid.Create(formul.Scrollbox2) Do
Begin
name:='stringgrid'+inttostr(i+2);
Parent := formul.Scrollbox2;
colcount:=2;
rowcount:=sommet+1;
Cells[0,0]:='Flot N° '+inttostr(i);
Options:=Options+[goEditing];
width:=160;
for j:=1 to sommet do Cells[0,j]:=chr(64+j);
left:=(i-1)*164;
End;
// formulation
// formuler fonction objectif
memo1.Lines[0]:='Min ';
for i:=1 to nflux do
for j:=1 to arc do memo1.Lines[0]:=memo1.Lines[0]+'C'+inttostr(j)+inttostr(i)+' '+'X'+inttostr(j)+inttostr(i)+'+';
memo1.Lines[0]:=copy(memo1.Lines[0],0,length(memo1.Lines[0])-1);
//formuler AXk=rk
ligne_memo:=1;
for k:=1 to nflux do
for i:=2 to stringgrid1.RowCount do
begin
equation:='';
for j:=2 to stringgrid1.colCount do
begin
if stringgrid1.Cells[j,i]='1' then equation:=equation+'X'+inttostr(j)+inttostr(k);
if stringgrid1.Cells[j,i]='-1' then equation:=equation+'-X'+inttostr(j)+inttostr(k);
end;
if k=1 then equation:=equation+'='+formul.Scrollbox2.stringgrid3.cell[2,i];
if k=2 then equation:=equation+'='+Scrollbox2.stringgrid4.cell[2,i];
if k=3 then equation:=equation+'='+scrollbox2.stringgrid5.cell[2,i];
memo1.lines[ligne_memo]:=equation;
ligne_memo:=ligne_memo+1;
end;
//formuler xij <= bij
end;
end. |
Partager