-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClTests.java
813 lines (665 loc) · 24.5 KB
/
ClTests.java
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
// $Id$
//
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This Java Implementation by Greg J. Badros, <[email protected]>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// ClTests.java
// run as:
// java -classpath ./classes EDU.Washington.grad.gjb.cassowary.ClTests testNum Cns Solvers Resolves
package EDU.Washington.grad.gjb.cassowary;
import java.lang.*;
import java.util.Random;
import java.util.Vector;
import java.io.FileReader;
import java.io.BufferedReader;
public class ClTests extends CL {
public ClTests()
{
RND = new Random();
}
public final static boolean simple1()
throws ExCLInternalError, ExCLRequiredFailure
{
boolean fOkResult = true;
ClVariable x = new ClVariable(167);
ClVariable y = new ClVariable(2);
ClSimplexSolver solver = new ClSimplexSolver();
// solver.addStay(x);
// solver.addStay(y);
ClLinearEquation eq = new ClLinearEquation(x,new ClLinearExpression(y));
solver.addConstraint(eq);
fOkResult = (x.value() == y.value());
System.out.println("x == " + x.value());
System.out.println("y == " + y.value());
return(fOkResult);
}
public final static boolean justStay1()
throws ExCLInternalError, ExCLRequiredFailure
{
boolean fOkResult = true;
ClVariable x = new ClVariable(5);
ClVariable y = new ClVariable(10);
ClSimplexSolver solver = new ClSimplexSolver();
solver.addStay(x);
solver.addStay(y);
fOkResult = fOkResult && CL.approx(x,5);
fOkResult = fOkResult && CL.approx(y,10);
System.out.println("x == " + x.value());
System.out.println("y == " + y.value());
return(fOkResult);
}
public final static boolean addDelete1()
throws ExCLInternalError, ExCLRequiredFailure, ExCLConstraintNotFound
{
boolean fOkResult = true;
ClVariable x = new ClVariable("x");
ClSimplexSolver solver = new ClSimplexSolver();
solver.addConstraint( new ClLinearEquation( x, 100, ClStrength.weak ) );
ClLinearInequality c10 = new ClLinearInequality(x,CL.LEQ,10.0);
ClLinearInequality c20 = new ClLinearInequality(x,CL.LEQ,20.0);
solver
.addConstraint(c10)
.addConstraint(c20);
fOkResult = fOkResult && CL.approx(x,10.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c10);
fOkResult = fOkResult && CL.approx(x,20.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c20);
fOkResult = fOkResult && CL.approx(x,100.0);
System.out.println("x == " + x.value());
ClLinearInequality c10again = new ClLinearInequality(x,CL.LEQ,10.0);
solver
.addConstraint(c10)
.addConstraint(c10again);
fOkResult = fOkResult && CL.approx(x,10.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c10);
fOkResult = fOkResult && CL.approx(x,10.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c10again);
fOkResult = fOkResult && CL.approx(x,100.0);
System.out.println("x == " + x.value());
return(fOkResult);
}
public final static boolean addDelete2()
throws ExCLInternalError, ExCLRequiredFailure,
ExCLConstraintNotFound, ExCLNonlinearExpression
{
boolean fOkResult = true;
ClVariable x = new ClVariable("x");
ClVariable y = new ClVariable("y");
ClSimplexSolver solver = new ClSimplexSolver();
solver
.addConstraint( new ClLinearEquation(x, 100.0, ClStrength.weak))
.addConstraint( new ClLinearEquation(y, 120.0, ClStrength.strong));
ClLinearInequality c10 = new ClLinearInequality(x,CL.LEQ,10.0);
ClLinearInequality c20 = new ClLinearInequality(x,CL.LEQ,20.0);
solver
.addConstraint(c10)
.addConstraint(c20);
fOkResult = fOkResult && CL.approx(x,10.0) && CL.approx(y,120.0);
System.out.println("x == " + x.value() + ", y == " + y.value());
solver.removeConstraint(c10);
fOkResult = fOkResult && CL.approx(x,20.0) && CL.approx(y,120.0);
System.out.println("x == " + x.value() + ", y == " + y.value());
ClLinearEquation cxy = new ClLinearEquation( CL.Times(2.0,x), y);
solver.addConstraint(cxy);
fOkResult = fOkResult && CL.approx(x,20.0) && CL.approx(y,40.0);
System.out.println("x == " + x.value() + ", y == " + y.value());
solver.removeConstraint(c20);
fOkResult = fOkResult && CL.approx(x,60.0) && CL.approx(y,120.0);
System.out.println("x == " + x.value() + ", y == " + y.value());
solver.removeConstraint(cxy);
fOkResult = fOkResult && CL.approx(x,100.0) && CL.approx(y,120.0);
System.out.println("x == " + x.value() + ", y == " + y.value());
return(fOkResult);
}
public final static boolean casso1()
throws ExCLInternalError, ExCLRequiredFailure
{
boolean fOkResult = true;
ClVariable x = new ClVariable("x");
ClVariable y = new ClVariable("y");
ClSimplexSolver solver = new ClSimplexSolver();
solver
.addConstraint( new ClLinearInequality(x,CL.LEQ,y) )
.addConstraint( new ClLinearEquation(y, CL.Plus(x,3.0)) )
.addConstraint( new ClLinearEquation(x,10.0,ClStrength.weak) )
.addConstraint( new ClLinearEquation(y,10.0,ClStrength.weak) )
;
fOkResult = fOkResult &&
( CL.approx(x,10.0) && CL.approx(y,13.0) ||
CL.approx(x,7.0) && CL.approx(y,10.0) );
System.out.println("x == " + x.value() + ", y == " + y.value());
return(fOkResult);
}
public final static boolean inconsistent1()
throws ExCLInternalError, ExCLRequiredFailure
{
try
{
ClVariable x = new ClVariable("x");
ClSimplexSolver solver = new ClSimplexSolver();
solver
.addConstraint( new ClLinearEquation(x,10.0) )
.addConstraint( new ClLinearEquation(x, 5.0) );
// no exception, we failed!
return(false);
}
catch (ExCLRequiredFailure err)
{
// we want this exception to get thrown
System.out.println("Success -- got the exception");
return(true);
}
}
public final static boolean inconsistent2()
throws ExCLInternalError, ExCLRequiredFailure
{
try
{
ClVariable x = new ClVariable("x");
ClSimplexSolver solver = new ClSimplexSolver();
solver
.addConstraint( new ClLinearInequality(x,CL.GEQ,10.0) )
.addConstraint( new ClLinearInequality(x,CL.LEQ, 5.0) );
// no exception, we failed!
return(false);
}
catch (ExCLRequiredFailure err)
{
// we want this exception to get thrown
System.out.println("Success -- got the exception");
return(true);
}
}
public final static boolean multiedit()
throws ExCLInternalError, ExCLRequiredFailure, ExCLError
{
try
{
boolean fOkResult = true;
ClVariable x = new ClVariable("x");
ClVariable y = new ClVariable("y");
ClVariable w = new ClVariable("w");
ClVariable h = new ClVariable("h");
ClSimplexSolver solver = new ClSimplexSolver();
solver
.addStay(x)
.addStay(y)
.addStay(w)
.addStay(h);
solver
.addEditVar(x)
.addEditVar(y)
.beginEdit();
solver
.suggestValue(x,10)
.suggestValue(y,20)
.resolve();
System.out.println("x = " + x.value() + "; y = " + y.value());
System.out.println("w = " + w.value() + "; h = " + h.value());
fOkResult = fOkResult &&
CL.approx(x,10) && CL.approx(y,20) &&
CL.approx(w,0) && CL.approx(h,0);
solver
.addEditVar(w)
.addEditVar(h)
.beginEdit();
solver
.suggestValue(w,30)
.suggestValue(h,40)
.endEdit();
System.out.println("x = " + x.value() + "; y = " + y.value());
System.out.println("w = " + w.value() + "; h = " + h.value());
fOkResult = fOkResult &&
CL.approx(x,10) && CL.approx(y,20) &&
CL.approx(w,30) && CL.approx(h,40);
solver
.suggestValue(x,50)
.suggestValue(y,60)
.endEdit();
System.out.println("x = " + x.value() + "; y = " + y.value());
System.out.println("w = " + w.value() + "; h = " + h.value());
fOkResult = fOkResult &&
CL.approx(x,50) && CL.approx(y,60) &&
CL.approx(w,30) && CL.approx(h,40);
return(fOkResult);
}
catch (ExCLRequiredFailure err)
{
// we want this exception to get thrown
System.out.println("Success -- got the exception");
return(true);
}
}
public final static boolean inconsistent3()
throws ExCLInternalError, ExCLRequiredFailure
{
try
{
ClVariable w = new ClVariable("w");
ClVariable x = new ClVariable("x");
ClVariable y = new ClVariable("y");
ClVariable z = new ClVariable("z");
ClSimplexSolver solver = new ClSimplexSolver();
solver
.addConstraint( new ClLinearInequality(w,CL.GEQ,10.0) )
.addConstraint( new ClLinearInequality(x,CL.GEQ,w) )
.addConstraint( new ClLinearInequality(y,CL.GEQ,x) )
.addConstraint( new ClLinearInequality(z,CL.GEQ,y) )
.addConstraint( new ClLinearInequality(z,CL.GEQ,8.0) )
.addConstraint( new ClLinearInequality(z,CL.LEQ, 4.0) );
// no exception, we failed!
return(false);
}
catch (ExCLRequiredFailure err)
{
// we want this exception to get thrown
System.out.println("Success -- got the exception");
return(true);
}
}
public final static boolean addDel(int nCns, int nVars, int nResolves)
throws ExCLInternalError, ExCLRequiredFailure,
ExCLNonlinearExpression, ExCLConstraintNotFound
{
Timer timer = new Timer();
// FIXGJB: from where did .12 come?
final double ineqProb = 0.12;
final int maxVars = 3;
InitializeRandoms();
System.out.println("starting timing test. nCns = " + nCns +
", nVars = " + nVars + ", nResolves = " + nResolves);
timer.Start();
ClSimplexSolver solver = new ClSimplexSolver();
solver.setAutosolve(false);
ClVariable[] rgpclv = new ClVariable[nVars];
for (int i = 0; i < nVars; i++) {
rgpclv[i] = new ClVariable(i,"x");
solver.addStay(rgpclv[i]);
}
int nCnsMade = nCns*2;
ClConstraint[] rgpcns = new ClConstraint[nCnsMade];
ClConstraint[] rgpcnsAdded = new ClConstraint[nCns];
int nvs = 0;
int k;
int j;
double coeff;
for (j = 0; j < nCnsMade; ++j) {
// number of variables in this constraint
nvs = RandomInRange(1,maxVars);
if (fTraceOn) traceprint("Using nvs = " + nvs);
ClLinearExpression expr = new ClLinearExpression(UniformRandomDiscretized() * 20.0 - 10.0);
for (k = 0; k < nvs; k++) {
coeff = UniformRandomDiscretized()*10 - 5;
int iclv = (int) (UniformRandomDiscretized()*nVars);
expr.addExpression(CL.Times(rgpclv[iclv], coeff));
}
if (UniformRandomDiscretized() < ineqProb) {
rgpcns[j] = new ClLinearInequality(expr);
} else {
rgpcns[j] = new ClLinearEquation(expr);
}
if (fTraceOn) traceprint("Constraint " + j + " is " + rgpcns[j]);
}
timer.Stop();
System.out.println("done building data structures");
System.out.println("time = " + timer.ElapsedTime());
timer.Reset();
timer.Start();
int cExceptions = 0;
int cCns = 0;
for (j = 0; j < nCnsMade && cCns < nCns; j++) {
// add the constraint -- if it's incompatible, just ignore it
// FIXGJB: exceptions are extra expensive in C++, so this might not
// be particularly fair
try
{
solver.addConstraint(rgpcns[j]);
rgpcnsAdded[cCns++] = rgpcns[j];
if (fTraceAdded) traceprint("Added cn: " + rgpcns[j]);
}
catch (ExCLRequiredFailure err)
{
cExceptions++;
if (fTraceOn) traceprint("got exception adding " + rgpcns[j]);
if (fTraceAdded) traceprint("got exception adding " + rgpcns[j]);
rgpcns[j] = null;
}
}
solver.solve();
timer.Stop();
System.out.println("done adding " + cCns + " constraints ["
+ j + " attempted, "
+ cExceptions + " exceptions]");
System.out.println("time = " + timer.ElapsedTime() + "\n");
System.out.println("time per Add cn = " + timer.ElapsedTime()/cCns);
int e1Index = (int) (UniformRandomDiscretized()*nVars);
int e2Index = (int) (UniformRandomDiscretized()*nVars);
System.out.println("Editing vars with indices " + e1Index + ", " + e2Index);
ClEditConstraint edit1 = new ClEditConstraint(rgpclv[e1Index],ClStrength.strong);
ClEditConstraint edit2 = new ClEditConstraint(rgpclv[e2Index],ClStrength.strong);
// CL.fDebugOn = CL.fTraceOn = true;
System.out.println("about to start resolves");
timer.Reset();
timer.Start();
solver
.addConstraint(edit1)
.addConstraint(edit2);
timer.Stop();
for (int m = 0; m < nResolves; m++)
{
solver.resolve(rgpclv[e1Index].value() * 1.001,
rgpclv[e2Index].value() * 1.001);
}
solver.removeConstraint(edit1);
solver.removeConstraint(edit2);
timer.Stop();
System.out.println("done resolves -- now removing constraints");
System.out.println("time = " + timer.ElapsedTime() + "\n");
System.out.println("time per Resolve = " + timer.ElapsedTime()/nResolves);
timer.Reset();
timer.Start();
for (j = 0; j < cCns; j++)
{
solver.removeConstraint(rgpcnsAdded[j]);
// System.out.println("removing #" + j);
}
// solver.solve();
timer.Stop();
System.out.println("done removing constraints and addDel timing test");
System.out.println("time = " + timer.ElapsedTime() + "\n");
System.out.println("time per Remove cn = " + timer.ElapsedTime()/cCns);
return true;
}
public final static void InitializeRandomsFromFile() {
try {
iRandom = 0;
String s;
FileReader in = new FileReader("randoms.txt");
BufferedReader reader = new BufferedReader(in);
vRandom = new Vector(20001);
// skip over comment
reader.readLine();
// skip over number of randoms
reader.readLine();
Double f;
while ((s = reader.readLine()) != null) {
f = Double.valueOf(s);
vRandom.add(f);
++cRandom;
}
System.err.println("Read in " + cRandom + " random numbers");
} catch (java.io.IOException e) {
// nothing
}
}
public final static void InitializeRandoms() {
// do nothing
}
public final static double UniformRandomDiscretized()
{
double n = Math.abs(RND.nextInt());
return (n/Integer.MAX_VALUE);
}
public final static double UniformRandomDiscretizedFromFile()
{
if (iRandom >= cRandom) {
// throw new Exception("Out of random numbers");
return -1;
}
double f = ((Double)vRandom.elementAt(iRandom++)).doubleValue();
// System.out.println("returning value = " + f);
return f;
}
public final static double GrainedUniformRandom()
{
final double grain = 1.0e-4;
double n = UniformRandomDiscretized();
double answer = ((int)(n/grain))*grain;
return answer;
}
public final static int RandomInRange(int low, int high)
{
return (int) (UniformRandomDiscretized()*(high-low+1))+low;
}
public final static boolean addDelSolvers(int nCns, int nResolves, int nSolvers, int testNum)
throws ExCLInternalError, ExCLRequiredFailure,
ExCLNonlinearExpression, ExCLConstraintNotFound
{
Timer timer = new Timer();
double tmAdd, tmEdit, tmResolve, tmEndEdit;
// FIXGJB: from where did .12 come?
final double ineqProb = 0.12;
final int maxVars = 3;
final int nVars = nCns;
InitializeRandoms();
System.err.println("starting timing test. nCns = " + nCns +
", nSolvers = " + nSolvers + ", nResolves = " + nResolves);
timer.Start();
ClSimplexSolver[] rgsolvers = new ClSimplexSolver[nSolvers+1];
for (int is = 0; is < nSolvers+1; ++is) {
rgsolvers[is] = new ClSimplexSolver();
rgsolvers[is].setAutosolve(false);
}
ClVariable[] rgpclv = new ClVariable[nVars];
for (int i = 0; i < nVars; i++) {
rgpclv[i] = new ClVariable(i,"x");
for (int is = 0; is < nSolvers+1; ++is) {
rgsolvers[is].addStay(rgpclv[i]);
}
}
int nCnsMade = nCns*5;
ClConstraint[] rgpcns = new ClConstraint[nCnsMade];
ClConstraint[] rgpcnsAdded = new ClConstraint[nCns];
int nvs = 0;
int k;
int j;
double coeff;
for (j = 0; j < nCnsMade; ++j) {
// number of variables in this constraint
nvs = RandomInRange(1,maxVars);
if (fTraceOn) traceprint("Using nvs = " + nvs);
ClLinearExpression expr = new ClLinearExpression(GrainedUniformRandom() * 20.0 - 10.0);
for (k = 0; k < nvs; k++) {
coeff = GrainedUniformRandom()*10 - 5;
int iclv = (int) (UniformRandomDiscretized()*nVars);
expr.addExpression(CL.Times(rgpclv[iclv], coeff));
}
if (UniformRandomDiscretized() < ineqProb) {
rgpcns[j] = new ClLinearInequality(expr);
} else {
rgpcns[j] = new ClLinearEquation(expr);
}
if (fTraceOn) traceprint("Constraint " + j + " is " + rgpcns[j]);
}
timer.Stop();
System.err.println("done building data structures");
for (int is = 0; is < nSolvers; ++is) {
int cCns = 0;
int cExceptions = 0;
ClSimplexSolver solver = rgsolvers[nSolvers];
cExceptions = 0;
for (j = 0; j < nCnsMade && cCns < nCns; j++) {
try
{
if (null != rgpcns[j]) {
solver.addConstraint(rgpcns[j]);
// System.out.println("Added " + j + " = " + rgpcns[j]);
++cCns;
}
}
catch (ExCLRequiredFailure err)
{
cExceptions++;
rgpcns[j] = null;
}
}
}
timer.Reset();
timer.Start();
for (int is = 0; is < nSolvers; ++is) {
int cCns = 0;
int cExceptions = 0;
ClSimplexSolver solver = rgsolvers[is];
cExceptions = 0;
for (j = 0; j < nCnsMade && cCns < nCns; j++) {
// add the constraint -- if it's incompatible, just ignore it
try
{
if (null != rgpcns[j]) {
solver.addConstraint(rgpcns[j]);
// System.out.println("Added " + j + " = " + rgpcns[j]);
++cCns;
}
}
catch (ExCLRequiredFailure err)
{
cExceptions++;
rgpcns[j] = null;
}
}
System.err.println("done adding " + cCns + " constraints ["
+ j + " attempted, "
+ cExceptions + " exceptions]");
solver.solve();
}
timer.Stop();
tmAdd = timer.ElapsedTime();
int e1Index = (int) (UniformRandomDiscretized()*nVars);
int e2Index = (int) (UniformRandomDiscretized()*nVars);
System.err.println("Editing vars with indices " + e1Index + ", " + e2Index);
ClEditConstraint edit1 = new ClEditConstraint(rgpclv[e1Index],ClStrength.strong);
ClEditConstraint edit2 = new ClEditConstraint(rgpclv[e2Index],ClStrength.strong);
// CL.fDebugOn = CL.fTraceOn = true;
System.err.println("about to start resolves");
timer.Reset();
timer.Start();
for (int is = 0; is < nSolvers; ++is) {
rgsolvers[is]
.addConstraint(edit1)
.addConstraint(edit2);
}
timer.Stop();
tmEdit = timer.ElapsedTime();
timer.Reset();
timer.Start();
for (int is = 0; is < nSolvers; ++is) {
ClSimplexSolver solver = rgsolvers[is];
for (int m = 0; m < nResolves; m++)
{
solver.resolve(rgpclv[e1Index].value() * 1.001,
rgpclv[e2Index].value() * 1.001);
}
}
timer.Stop();
tmResolve = timer.ElapsedTime();
System.err.println("done resolves -- now ending edits");
timer.Reset();
timer.Start();
for (int is = 0; is < nSolvers; ++is) {
rgsolvers[is]
.removeConstraint(edit1)
.removeConstraint(edit2);
}
timer.Stop();
tmEndEdit = timer.ElapsedTime();
final int mspersec = 1000;
System.out.println(nCns + "," + nSolvers + "," + nResolves + "," + testNum + "," +
tmAdd*mspersec + "," + tmEdit*mspersec + "," + tmResolve*mspersec + "," + tmEndEdit*mspersec + "," +
tmAdd/nCns/nSolvers*mspersec + "," +
tmEdit/nSolvers/2*mspersec + "," +
tmResolve/nResolves/nSolvers*mspersec + "," +
tmEndEdit/nSolvers/2*mspersec);
return true;
}
public final static void main( String[] args )
throws ExCLInternalError, ExCLNonlinearExpression,
ExCLRequiredFailure, ExCLConstraintNotFound, ExCLError
{
try
{
ClTests clt = new ClTests();
boolean fAllOkResult = true;
boolean fResult;
if (true) {
System.out.println("\n\n\nsimple1:");
fResult = simple1(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\njustStay1:");
fResult = justStay1(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\naddDelete1:");
fResult = addDelete1(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\naddDelete2:");
fResult = addDelete2(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\ncasso1:");
fResult = casso1(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\ninconsistent1:");
fResult = inconsistent1(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\ninconsistent2:");
fResult = inconsistent2(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\ninconsistent3:");
fResult = inconsistent3(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
System.out.println("\n\n\nmultiedit:");
fResult = multiedit(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
}
System.out.println("\n\n\naddDel:");
int testNum = 1, cns = 900, resolves = 100, solvers = 10;
if (args.length > 0)
testNum = Integer.parseInt(args[0]);
if (args.length > 1)
cns = Integer.parseInt(args[1]);
if (args.length > 2)
solvers = Integer.parseInt(args[2]);
if (args.length > 3)
resolves = Integer.parseInt(args[3]);
if (false) {
fResult = addDel(cns,cns,resolves);
// fResult = addDel(300,300,1000);
// fResult = addDel(30,30,100);
// fResult = addDel(10,10,30);
// fResult = addDel(5,5,10);
fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
}
addDelSolvers(cns,resolves,solvers,testNum);
}
catch (Exception err)
{
ExCLError myerr = (ExCLError) err;
if (null != myerr) {
System.err.println("Exception: " + myerr + ": " + myerr.description());
} else {
System.err.println("Exception: " + err);
}
}
}
static private int iRandom = 0;
static private int cRandom = 0;
static private Vector vRandom;
static private Random RND;
}