summaryrefslogtreecommitdiff
path: root/stabile.lpr
blob: b65017e12259c7cd7d3b2d86310a6b7aad46b300 (plain)
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
program stabile;

uses grampsunit, sysutils, crt, grampstypen, grampsmath, matheunit;

var
  S:   String;
  c:   char;
  Stb: TStabile;

procedure Status(Level: Longint);
begin
 case Level of
   0:
     writeln('Fehler: obiger Fehler!');
   2:
     writeln('Fehler: Korrupte Zwischenstand-Datei!');
   else begin
     writeln('Verwendung: '+Paramstr(0)+' (e|E)[bM]* input.xml/input.gramps');
     writeln('oder:       '+Paramstr(0)+' l Zwischenzustand.txt');
   end;
 end{of case};
 if Assigned(Stb) then Stb.destroy;
 halt;
end;

begin
 if GetEnvironmentVariable('randseed')<>'' then
   randseed:=strtoint(GetEnvironmentVariable('randseed'));

 if (Paramcount<>2) or
    (length(Paramstr(1))<1) or
    ((length(Paramstr(1))<>1) and
     (leftStr(Paramstr(1),1)='l')) then Status(1);
 case Paramstr(1)[1] of
   'e','E': begin // aus gramps-xml lesen
     if ((rightStr(Paramstr(2),4)<>'.xml') and
         (rightStr(Paramstr(2),7)<>'.gramps')) or
        not fileexists(Paramstr(2)) then Status(1);
     Stb:=TStabile.create;
     if not Stb.LadeXML(Paramstr(2)) then begin
       Stb.destroy;
       halt;
     end;
     Stb.printStatus(0);
     Stb.generiereFehlendeInfos;
     Stb.printStatus(1);

     if (length(Paramstr(1))=1) or (pos('b',Paramstr(1))>0) or (pos('i',Paramstr(1))>0) then
       Stb.nurGroeszteZusammenhangskomponente;

     Stb.printStatus(2);
     if not Stb.analysiereInteraktionen then begin
       Stb.destroy;
       halt;
     end;
     Stb.printStatus(3);

     if Paramstr(1)[1]='E' then
       Stb.blaetterAbschneiden;

     Stb.Initialisiere(10000,rightStr(Paramstr(1),length(Paramstr(1))-1));
   end;
   'l': begin //  aus Zwischenstandsdatei einlesen
     if Paramcount<>2 then Status(1);
     if not fileexists(Paramstr(2)) then Status(1);
     Stb:=TStabile.create;
     if not Stb.LadeVonDatei(Paramstr(2)) then Status(2);
     Stb.printStatus(4);
   end;
 end{of Case};
// Stb.optimiere;
// Stb.downHillSimplex;
 Stb.gradientenOptimierung;
 writeln('Du hattest '+myTimeToStr(Stb.Zeit)+' Geduld.');
 write('Möchtest du den Fortschritt speichern? (j/n) ');
 c:=readkey;
 while not (c in ['j','J','n','N']) do begin
   writeln;
   writeln(''''+c+''' verstehe ich nicht, aber ich wiederhole die Frage gerne noch einmal:');
   write('Möchtest du den Fortschritt speichern? (j/n) ');
   c:=readkey;
 end;
 writeln;
 if c in ['j','J'] then begin
   writeln('Und wohin?');
   readln(S);
   while not Stb.SpeichereInDatei(S) do begin
     writeln('Die Datei '''+S+''' existiert bereits, nimm bitte eine andere!');
     readln(S);
   end;
 end;
 writeln;
 Stb.destroy;
end.