-
Notifications
You must be signed in to change notification settings - Fork 297
/
OnRelaxation.mo
3501 lines (3321 loc) · 126 KB
/
OnRelaxation.mo
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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package OnRelaxation "
file: OnRelaxation.mo
package: OnRelaxation
description: Relaxation for MultiBody Systems"
public import BackendDAE;
public import DAE;
protected
import AdjacencyMatrix;
import Array;
import BackendDAEEXT;
import BackendDAETransform;
import BackendDAEUtil;
import BackendDump;
import BackendEquation;
import BackendVariable;
import BaseHashSet;
import ComponentReference;
import Differentiate;
import DumpGraphML;
import Expression;
import ExpressionDump;
import ExpressionSimplify;
import HashSet;
import List;
import Matching;
import MetaModelica.Dangerous;
import Sorting;
import SymbolicJacobian;
import Util;
/*
* relaxation from gausian elemination
*
*/
public function relaxSystem "author: Frenkel TUD 2011-05"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
(outDAE, _) := BackendDAEUtil.mapEqSystemAndFold(inDAE, relaxSystem0, false);
end relaxSystem;
protected function relaxSystem0 "author: Frenkel TUD 2011-05"
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared inShared;
input Boolean inChanged;
output BackendDAE.EqSystem osyst;
output BackendDAE.Shared outShared;
output Boolean outChanged;
protected
BackendDAE.StrongComponents comps;
Boolean b, b1, b2;
BackendDAE.Shared shared;
BackendDAE.EqSystem syst;
algorithm
BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps)) := isyst;
(osyst, outShared, b2) := relaxSystem1(isyst, inShared, comps);
outChanged := inChanged or b2;
end relaxSystem0;
protected function relaxSystem1 "author: Frenkel TUD 2011-05"
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input BackendDAE.StrongComponents inComps;
output BackendDAE.EqSystem osyst;
output BackendDAE.Shared oshared;
output Boolean outRunMatching;
algorithm
(osyst, oshared, outRunMatching):=
matchcontinue (isyst, ishared, inComps)
local
list<Integer> eindex, vindx, eorphans, vorphans, unassigned, otherorphans, roots, constraints, constraintresidual;
Boolean b, b1;
BackendDAE.EqSystem syst, subsyst;
BackendDAE.Shared shared;
BackendDAE.StrongComponents comps;
BackendDAE.StrongComponent comp, comp1;
array<Integer> ass1, ass2, vec2, rowmarks, colummarks, mapIncRowEqn, orowmarks, ocolummarks;
Integer size, mark, esize;
list<BackendDAE.Equation> eqn_lst;
list<BackendDAE.Var> var_lst;
BackendDAE.Variables vars, tvars;
BackendDAE.EquationArray eqns, teqns;
BackendDAE.AdjacencyMatrix m, m1, mc;
BackendDAE.AdjacencyMatrixT mt, mct;
list<tuple<Integer, Integer, BackendDAE.Equation>> jac;
list<DAE.Exp> beqs;
array<list<tuple<Integer, DAE.Exp>>> matrix;
array<DAE.Exp> crefexps;
list<DAE.Exp> crefexplst;
array<list<Integer>> vorphansarray1, mapEqnIncRow, ass22, vec1;
list<BackendDAE.Equation> neweqns;
DAE.FunctionTree funcs;
case (_, _, {})
then (isyst, ishared, false);
case (_, shared as BackendDAE.SHARED(functionTree=funcs),
(BackendDAE.EQUATIONSYSTEM(eqns=eindex, vars=vindx, jac=BackendDAE.FULL_JACOBIAN(SOME(jac)), jacType=BackendDAE.JAC_LINEAR()))::comps)
equation
print("try to relax\n");
Util.profilerinit();
Util.profilerstart2();
Util.profilerstart1();
size = listLength(vindx);
esize = listLength(eindex);
ass1 = arrayCreate(size, -1);
ass2 = arrayCreate(size, -1);
eqn_lst = BackendEquation.getList(eindex, BackendEquation.getEqnsFromEqSystem(isyst));
eqns = BackendEquation.listEquation(eqn_lst);
var_lst = List.map1r(vindx, BackendVariable.getVarAt, BackendVariable.daeVars(isyst));
vars = BackendVariable.listVar1(var_lst);
subsyst = BackendDAEUtil.createEqSystem(vars, eqns);
(subsyst, m, mt, mapEqnIncRow, mapIncRowEqn) = BackendDAEUtil.getAdjacencyMatrixScalar(subsyst, BackendDAE.ABSOLUTE(), SOME(funcs), BackendDAEUtil.isInitializationDAE(ishared));
// BackendDump.dumpEqSystem(subsyst);
// Vector Matching a=f(..), f(..)=a
((_, ass1, ass2)) = List.fold1(eqn_lst, vectorMatching, vars, (1, ass1, ass2));
// Alias Matching only if one side is matched
((_, ass1, ass2)) = List.fold1(eqn_lst, aliasMatching, vars, (1, ass1, ass2));
// Vector matching
m1 = arrayCreate(size, {});
transformJacToAdjacencyMatrix2(jac, m1, mapIncRowEqn, eqns, ass1, ass2, isConstOneMinusOne);
Matching.matchingExternalsetAdjacencyMatrix(size, size, m1);
true = BackendDAEEXT.setAssignment(size, size, ass2, ass1);
BackendDAEEXT.matching(size, size, 5, -1, 1.0, 0);
BackendDAEEXT.getAssignment(ass2, ass1);
// Natural Matching - seems not to be good enough
//((_, ass1, ass2)) = List.fold1(eqn_lst, naturalMatching, vars, (1, ass1, ass2));
//((_, ass1, ass2)) = List.fold1(eqn_lst, naturalMatching1, vars, (1, ass1, ass2));
//((_, ass1, ass2)) = List.fold1(eqn_lst, naturalMatching2, vars, (1, ass1, ass2));
// subsyst = BackendDAEUtil.setEqSystemMatching(subsyst, BackendDAE.MATCHING(ass1, ass2, {}));
// DumpGraphML.dumpSystem(subsyst, shared, NONE(), intString(size) + "SystemVectorMatching.graphml");
// BackendDump.dumpMatching(ass1);
// BackendDump.dumpMatching(ass2);
// Boeser hack fuer FourBar
/*
(subsyst, m, mt, mapEqnIncRow, mapIncRowEqn) = BackendDAEUtil.getAdjacencyMatrixScalar(subsyst, BackendDAE.ABSOLUTE(), SOME(funcs));
temp::_ = mapEqnIncRow[72];
arrayUpdate(ass1, 90, temp);
arrayUpdate(ass2, temp, 90);
temp::_ = mapEqnIncRow[97];
arrayUpdate(ass1, 125, temp);
arrayUpdate(ass2, temp, 125);
temp::_ = mapEqnIncRow[99];
arrayUpdate(ass1, 128, temp);
arrayUpdate(ass2, temp, 128);
subsyst = BackendDAEUtil.setEqSystemMatching(subsyst, BackendDAE.MATCHING(ass1, ass2, {}));
DumpGraphML.dumpSystem(subsyst, shared, NONE(), intString(size) + "SystemHackMatching.graphml");
*/
// Matching based on Enhanced Adiacency Matrix, take care of the solvability - theems to be good but not good enough
// (subsyst, _, _) = BackendDAEUtil.getAdjacencyMatrix(subsyst, BackendDAE.ABSOLUTE(), SOME(funcs), BackendDAEUtil.isInitializationDAE(shared));
// BackendDump.dumpEqSystem(subsyst);
// dumpJacMatrix(jac, 1, 1, size, vars);
m1 = arrayCreate(size, {});
//mt1 = arrayCreate(size, {});
transformJacToAdjacencyMatrix1(jac, m1, ass1, ass2, isConstOneMinusOne);
// BackendDump.dumpAdjacencyMatrix(m1);
// BackendDump.dumpAdjacencyMatrixT(mt1);
//transformJacToAdjacencyMatrix(jac, 1, 1, size, m1, mt1, isConstOneMinusOne);
Matching.matchingExternalsetAdjacencyMatrix(size, size, m1);
true = BackendDAEEXT.setAssignment(size, size, ass2, ass1);
BackendDAEEXT.matching(size, size, 1, -1, 1.0, 0);
BackendDAEEXT.getAssignment(ass2, ass1);
// subsyst = BackendDAEUtil.setEqSystemMatching(subsyst, BackendDAE.MATCHING(ass1, ass2, {}));
// DumpGraphML.dumpSystem(subsyst, shared, NONE(), intString(size) + "SystemOneMatching.graphml");
// BackendDump.dumpMatching(ass1);
// BackendDump.dumpMatching(ass2);
// onefreeMatching
// print("mapEqnIncRow:\n");
// BackendDump.dumpAdjacencyMatrix(mapEqnIncRow);
unassigned = Matching.getUnassigned(size, ass2, {});
colummarks = arrayCreate(size, -1);
onefreeMatchingBFS(unassigned, m, mt, size, ass1, ass2, colummarks, 1, {});
// BackendDump.dumpMatching(ass1);
// BackendDump.dumpMatching(ass2);
// subsyst = BackendDAEUtil.setEqSystemMatching(subsyst, BackendDAE.MATCHING(ass1, ass2, {}));
// DumpGraphML.dumpSystem(subsyst, shared, NONE(), intString(size) + "SystemOneFreeMatching.graphml");
// hier sollte zur vorsicht noch mal ein matching durchgefuehrt werden
Util.profilerstop1();
print("Matching time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
// collect tearing variables and residual equations
vorphans = getOrphans(1, size, ass1, {});
eorphans = getOrphans(1, size, ass2, {});
// print("Var Orphans: \n");
// BackendDump.debuglst((vorphans, intString, ", ", "\n"));
// print("Equation Orphans: \n");
// BackendDump.debuglst((eorphans, intString, ", ", "\n"));
// transform to nonscalar
ass1 = BackendDAETransform.varAssignmentNonScalar(ass1, mapIncRowEqn);
ass22 = BackendDAETransform.eqnAssignmentNonScalar(mapEqnIncRow, ass2);
eorphans = List.uniqueIntN(List.map1r(eorphans, arrayGet, mapIncRowEqn), arrayLength(mapIncRowEqn));
(subsyst, m, mt) = BackendDAEUtil.getAdjacencyMatrix(subsyst, BackendDAE.ABSOLUTE(), SOME(funcs), BackendDAEUtil.isInitializationDAE(ishared));
// BackendDump.dumpAdjacencyMatrix(m);
// BackendDump.dumpAdjacencyMatrixT(mt);
// genereate cliques
rowmarks = arrayCreate(size, -1);
colummarks = arrayCreate(size, -1);
orowmarks = arrayCreate(size, -1);
ocolummarks = arrayCreate(size, -1);
vorphansarray1 = arrayCreate(size, {});
mc = arrayCreate(esize, {});
mct = arrayCreate(size, {});
mc = Array.copy(m, mc);
mct = Array.copy(mt, mct);
mark = 1 "init mark value";
(mark, constraintresidual) = generateCliquesResidual(eorphans, ass1, ass22, mc, mct, mark, rowmarks, colummarks, vars, {}) "generate cliques for residual equations";
// print("constraintresidual: \n");
// BackendDump.debuglst((constraintresidual, intString, ", ", "\n"));
(mark, roots, constraints) = prepairOrphansOrder(vorphans, ass1, ass22, mc, mct, mark, rowmarks, colummarks, vorphansarray1, vars, {}, {}) "generate cliques for tearing vars";
mark = prepairOrphansOrder2(vorphans, ass1, ass22, mc, mct, mark, rowmarks, colummarks, vorphansarray1);
// subsyst = BackendDAE.EQSYSTEM(vars, eqns, SOME(mc), SOME(mct), BackendDAE.NO_MATCHING(), {});
// DumpGraphML.dumpSystem(subsyst, shared, NONE(), intString(size) + "SystemPreIndex.graphml");
// print("roots:\n");
// BackendDump.debuglst((roots, intString, ", ", "\n"));
// print("constraints:\n");
// BackendDump.debuglst((constraints, intString, ", ", "\n"));
Util.profilerstop1();
print("Identifikation time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
// Order of orphans
vorphansarray1 = arrayCreate(size, {});
List.map2_0(roots, doMark, rowmarks, mark);
List.map2_0(constraints, doMark, rowmarks, mark);
otherorphans = List.select2(vorphans, unmarked, rowmarks, mark);
// print("otherorphans:\n");
// BackendDump.debuglst((otherorphans, intString, ", ", "\n"));
mark = getOrphansOrderEdvanced(otherorphans, ass1, ass22, m, mt, mc, mct, mark, rowmarks, colummarks, vorphansarray1);
List.map2_0(otherorphans, removeRootConnections, vorphansarray1, roots);
mark = getConstraintesOrphansOrderEdvanced(constraints, ass1, ass22, m, mt, mc, mct, mark, rowmarks, colummarks, vorphansarray1);
// print("getOrphansOrderEdvanced:\n");
// BackendDump.dumpAdjacencyMatrix(vorphansarray1);
(vorphans, mark) = getOrphansOrderEdvanced3(roots, otherorphans, constraints, vorphans, vorphansarray1, mark, rowmarks);
Util.profilerstop1();
print("Reihenfolge time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
List.map2_0(constraints, doMark, rowmarks, mark);
otherorphans = List.select2(vorphans, unmarked, rowmarks, mark);
// print("sorted Var Orphans: \n");
// List.map1_0(vorphans, dumpVar, vars);
// BackendDump.debuglst((vorphans, intString, ", ", "\n"));
// BackendDump.dumpVarsArray(vars);
// get pairs of orphans
List.map2_0(constraintresidual, doAssign, ass22, {-1});
mark = getOrphansPairs(otherorphans, ass1, ass22, m, mt, mark+1, rowmarks, colummarks);
List.map2_0(constraintresidual, doAssign, ass22, {});
mark = getOrphansPairsConstraints(constraints, ass1, ass22, mc, mct, mark, rowmarks, colummarks, eqns);
// print("Matching with Orphans:\n");
// BackendDump.dumpMatching(ass1);
// BackendDump.dumpAdjacencyMatrix(ass22);
Util.profilerstop1();
print("Paarung time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
vec1 = arrayCreate(esize, {});
vec2 = arrayCreate(esize, -1);
orowmarks = List.fold1(vorphans, markOrphans, 1, orowmarks);
ocolummarks = List.fold1(eorphans, markOrphans, 1, ocolummarks);
mark = getIndexesForEqnsAdvanced(vorphans, 1, m, mt, mark, rowmarks, colummarks, orowmarks, ocolummarks, ass1, ass22, vec1, vec2, arrayCreate(esize, false), vars, eqns, shared, size);
// BackendDump.dumpAdjacencyMatrix(vec1);
// BackendDump.dumpMatching(vec2);
// vec3 = arrayCreate(size, -1);
// _ = List.fold1(arrayList(vec2), transposeOrphanVec, vec3, 1);
// DumpGraphML.dumpSystem(subsyst, shared, SOME(vec3), "System.graphml");
((_, _, _, eqns, vars)) = Array.fold(vec2, getEqnsinOrder, (eqns, vars, ass22, BackendEquation.listEquation({}), BackendVariable.emptyVars()));
Util.profilerstop1();
print("Indizierung time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
// replace evaluated parametes
//_ = BackendDAEUtil.traverseBackendDAEExpsEqns(eqns, replaceFinalParameter, BackendVariable.daeGlobalKnownVars(shared));
subsyst = BackendDAEUtil.createEqSystem(vars, eqns);
(subsyst, m, _) = BackendDAEUtil.getAdjacencyMatrix(subsyst, BackendDAE.ABSOLUTE(), SOME(funcs), BackendDAEUtil.isInitializationDAE(ishared));
// BackendDump.dumpEqSystem(subsyst);
// DumpGraphML.dumpSystem(subsyst, shared, NONE(), intString(size) + "SystemIndexed.graphml");
(SOME(jac), _) = SymbolicJacobian.calculateJacobian(vars, eqns, m, true, ishared);
(beqs, _) = BackendDAEUtil.getEqnSysRhs(eqns, vars, SOME(funcs));
beqs = listReverse(beqs);
// print("Jacobian:\n");
// print(BackendDump.dumpJacobianStr(SOME(jac)) + "\n");
// dumpJacMatrix(jac, 1, 1, size, vars);
matrix = arrayCreate(size, {});
transformJacToMatrix(jac, 1, 1, size, beqs, matrix);
// print("Jacobian as Matrix:\n");
// dumpMatrix(1, size, matrix);
(tvars, teqns) = gaussElimination(1, size, matrix, BackendVariable.emptyVars(), BackendEquation.listEquation({}), (1, 1));
// dumpMatrix(1, size, matrix);
// subsyst = BackendDAEUtil.createEqSystem(tvars, teqns);
// BackendDump.dumpEqSystem(subsyst);
eqn_lst = BackendEquation.equationList(teqns);
var_lst = BackendVariable.varList(tvars);
syst = List.fold(eqn_lst, BackendEquation.equationAddDAE, isyst);
syst = List.fold(var_lst, BackendVariable.addVarDAE, syst);
crefexplst = List.map(BackendVariable.varList(vars), makeCrefExps);
crefexps = listArray(crefexplst);
neweqns = makeGausElimination(1, size, matrix, crefexps, {});
Util.profilerstop1();
print("Gaus Elimination time: " + realString(Util.profilertime1()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
syst = replaceEquationsAddNew(eindex, neweqns, syst);
Util.profilerstop2();
print("Gesamt time: " + realString(Util.profilertime2()) + "\n");
Util.profilerreset1();
Util.profilerstart1();
/*
vars = BackendVariable.addVars(var_lst, vars);
eqns = BackendEquation.addList(neweqns, teqns);
subsyst = BackendDAEUtil.createEqSystem(vars, eqns);
(subsyst, m, mt, mapEqnIncRow, mapIncRowEqn) = BackendDAEUtil.getAdjacencyMatrixScalar(subsyst, BackendDAE.NORMAL(), SOME(funcs));
print("Relaxed System:\n");
BackendDump.dumpEqSystem(subsyst);
size = arrayLength(m);
Matching.matchingExternalsetAdjacencyMatrix(size, size, m);
ass1 = arrayCreate(size, -1);
ass2 = arrayCreate(size, -1);
BackendDAEEXT.matching(size, size, 5, -1, 1.0, 1);
BackendDAEEXT.getAssignment(ass2, ass1);
subsyst = BackendDAEUtil.setEqSystemMatching(subsyst, BackendDAE.MATCHING(ass1, ass2, {}));
(subsyst, othercomps) = BackendDAETransform.strongComponentsScalar(subsyst, shared, mapEqnIncRow, mapIncRowEqn);
print("Relaxed System:\n");
BackendDump.dumpEqSystem(subsyst);
*/
// (syst, _, _) = BackendDAEUtil.getAdjacencyMatrix(syst, BackendDAE.NORMAL(), SOME(funcs), BackendDAEUtil.isInitializationDAE(shared));
// BackendDump.dumpEqSystem(syst);
// (i1, i2, i3) = countOperations1(syst, shared);
// print("Add Operations: " + intString(i1) + "\n");
// print("Mul Operations: " + intString(i2) + "\n");
// print("Oth Operations: " + intString(i3) + "\n");
print("Ok system relaxed\n");
(syst, shared, _) = relaxSystem1(syst, shared, comps);
then
(syst, shared, true);
case (_, _, _::comps)
equation
(syst, shared, b) = relaxSystem1(isyst, ishared, comps);
then
(syst, shared, b);
end matchcontinue;
end relaxSystem1;
protected function removeRootConnections
input Integer orphan;
input array<list<Integer>> orphansarray;
input list<Integer> roots;
algorithm
_:= matchcontinue(orphan, orphansarray, roots)
local
list<Integer> lst;
case(_, _, _)
equation
lst = orphansarray[orphan];
true = intGt(listLength(lst), 1);
lst = List.fold1(roots, List.removeOnTrue, intEq, lst);
arrayUpdate(orphansarray, orphan, lst);
then
();
case(_, _, _)
then
();
end matchcontinue;
end removeRootConnections;
protected function replaceFinalParameter "author: Frenkel TUD 2012-06"
input tuple<DAE.Exp, BackendDAE.Variables> itpl;
output tuple<DAE.Exp, BackendDAE.Variables> outTpl;
protected
DAE.Exp e;
BackendDAE.Variables knvars;
Boolean b;
algorithm
(e, knvars) := itpl;
(e, (knvars, b)) := Expression.traverseExpBottomUp(e, traverserExpreplaceFinalParameter, (knvars, false));
(e, _) := ExpressionSimplify.condsimplify(b, e);
outTpl := (e, knvars);
end replaceFinalParameter;
protected function traverserExpreplaceFinalParameter "author: Frenkel TUD 2012-06"
input DAE.Exp inExp;
input tuple<BackendDAE.Variables, Boolean> tpl;
output DAE.Exp outExp;
output tuple<BackendDAE.Variables, Boolean> outTpl;
algorithm
(outExp, outTpl) := matchcontinue (inExp, tpl)
local
BackendDAE.Variables knvars;
DAE.Exp e, e1;
DAE.ComponentRef cr;
BackendDAE.Var v;
case (DAE.CREF(componentRef=cr), (knvars, _))
equation
(v::_, _) = BackendVariable.getVar(cr, knvars);
true = BackendVariable.isFinalVar(v);
e1 = BackendVariable.varBindExpStartValue(v);
then
(e1, (knvars, true));
else (inExp, tpl);
end matchcontinue;
end traverserExpreplaceFinalParameter;
protected function replaceEquationsAddNew
input list<Integer> inEqnIndxes;
input list<BackendDAE.Equation> inEqns;
input BackendDAE.EqSystem inEqSystem;
output BackendDAE.EqSystem outEqSystem;
algorithm
outEqSystem := match(inEqnIndxes, inEqns, inEqSystem)
local
Integer index;
list<Integer> indices;
BackendDAE.Equation eqn;
list<BackendDAE.Equation> eqns;
BackendDAE.EqSystem eqSystem;
BackendDAE.Variables orderedVars;
BackendDAE.EquationArray orderedEqs;
Option<BackendDAE.AdjacencyMatrix> m, mT;
BackendDAE.Matching matching;
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
case ({}, _, _)
then BackendEquation.equationsAddDAE(inEqns, inEqSystem);
case (index::indices, eqn::eqns, BackendDAE.EQSYSTEM(orderedEqs=orderedEqs)) equation
eqSystem = BackendDAEUtil.setEqSystEqs(inEqSystem, BackendEquation.setAtIndex(orderedEqs, index, eqn));
then replaceEquationsAddNew(indices, eqns, eqSystem);
end match;
end replaceEquationsAddNew;
protected function dumpVar "author: Frenkel TUD 2012-05"
input Integer id;
input BackendDAE.Variables vars;
protected
BackendDAE.Var v;
algorithm
v := BackendVariable.getVarAt(vars, id);
print(ComponentReference.printComponentRefStr(BackendVariable.varCref(v)));
print("\n");
end dumpVar;
protected function transposeOrphanVec "author: Frenkel TUD 2012-05"
input Integer c;
input array<list<Integer>> vec3;
input Integer inId;
output Integer outId;
algorithm
outId := matchcontinue(c, vec3, inId)
local list<Integer> lst;
case (_, _, _)
equation
true = intGt(c, 0);
lst = vec3[c];
arrayUpdate(vec3, c, inId::lst);
then
inId + 1;
else
inId + 1;
end matchcontinue;
end transposeOrphanVec;
protected function markOrphans "author: Frenkel TUD 2012-05"
input Integer o;
input Integer mark;
input array<Integer> rowmark;
output array<Integer> orowmark;
algorithm
orowmark := arrayUpdate(rowmark, o, mark);
end markOrphans;
protected function generateCliquesResidual "author: Frenkel TUD 2012-07"
input list<Integer> inOrphans;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input Integer mark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input BackendDAE.Variables vars;
input list<Integer> iconstraints;
output Integer omark;
output list<Integer> oconstraints;
algorithm
(omark, oconstraints) := matchcontinue(inOrphans, ass1, ass2, m, mt, mark, rowmarks, colummarks, vars, iconstraints)
local
list<Integer> rest, constraints, rlst, elst, partner;
Integer o;
Boolean foundflow;
list<Boolean> blst;
list<BackendDAE.Var> vlst;
case ({}, _, _, _, _, _, _, _, _, _)
then
(mark+2, iconstraints);
case (o::rest, _, _, _, _, _, _, _, _, _)
equation
false = intEq(colummarks[o], mark);
arrayUpdate(colummarks, o, mark);
// print("Process Residual " + intString(o) + "\n");
rlst = m[o];
// check for partner
elst = List.select1(List.flatten(List.map1r(rlst, arrayGet, mt)), intGt, 0);
// print("Search for " + intString(o) + " Parnters in: " + stringDelimitList(List.map(elst, intString), ", ") + "\n");
partner = List.select1(elst, isResOrphan, ass2);
partner = List.uniqueIntN(List.removeOnTrue(o, intEq, partner), arrayLength(colummarks));
List.map2_0(partner, doMark, colummarks, mark);
// print("Found for " + intString(o) + " Parnters: " + stringDelimitList(List.map(partner, intString), ", ") + "\n");
// BackendDump.debuglst((rlst, intString, ", ", "\n"));
vlst = List.map1r(rlst, BackendVariable.getVarAt, vars);
blst = List.map(vlst, BackendVariable.isFlowVar);
foundflow = Util.boolOrList(blst);
rlst = selectNonFlows(rlst, blst);
foundflow = generateCliquesResidual1(rlst, ass1, ass2, m, mt, mark, rowmarks, colummarks, foundflow, vars);
generateCliquesResidual2(rlst, ass1, ass2, m, mt, mark+1, rowmarks, colummarks, o::partner);
constraints = if not foundflow then listAppend(o::partner, iconstraints) else iconstraints;
(omark, constraints) = generateCliquesResidual(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, vars, constraints);
then
(omark, constraints);
case (_::rest, _, _, _, _, _, _, _, _, _)
equation
(omark, constraints) = generateCliquesResidual(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, vars, iconstraints);
then
(omark, constraints);
end matchcontinue;
end generateCliquesResidual;
protected function generateCliquesResidual1 "author: Frenkel TUD 2012-05"
input list<Integer> rows;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input Integer mark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input Boolean ifoundFlow;
input BackendDAE.Variables vars;
output Boolean ofoundFlow = ifoundFlow;
protected
Integer e;
list<Integer> next, rlst;
Boolean b1;
list<Boolean> blst;
list<BackendDAE.Var> vlst;
algorithm
for r in rows loop
if not intEq(rowmarks[r], mark) then
// remove orphans
next := List.select1(mt[r], isNoResOrphan, ass2);
// remove visited
next := List.select2(next, unmarked, colummarks, mark);
// remove assigned equation of this row
next := List.removeOnTrue(ass1[r], intEq, next);
if listEmpty(next) then
arrayUpdate(rowmarks, r, mark);
e := ass1[r];
// print("Go From " + intString(r) + " to " + intString(e) + "\n");
arrayUpdate(colummarks, e, mark);
rlst := ass2[e];
next := List.fold1(rlst, List.removeOnTrue, intEq, m[e]);
vlst := List.map1r(next, BackendVariable.getVarAt, vars);
blst := List.map(vlst, BackendVariable.isFlowVar);
b1 := Util.boolOrList(blst);
next := selectNonFlows(next, blst);
ofoundFlow := generateCliquesResidual1(next, ass1, ass2, m, mt, mark, rowmarks, colummarks, b1 or ofoundFlow, vars);
end if;
end if;
end for;
end generateCliquesResidual1;
protected function selectNonFlows
input list<Integer> rows;
input list<Boolean> flowFlag;
output list<Integer> oAcc = {};
protected
list<Boolean> brest = flowFlag;
Boolean b;
algorithm
for r in rows loop
b::brest := brest;
if not b then
oAcc := r::oAcc;
end if;
end for;
end selectNonFlows;
protected function generateCliquesResidual2 "author: Frenkel TUD 2012-05"
input list<Integer> eqns;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input Integer mark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input list<Integer> orphan;
algorithm
_ := match(eqns, ass1, ass2, m, mt, mark, rowmarks, colummarks, orphan)
local
Integer e, r;
list<Integer> rest, lst, rlst, lst1;
case ({}, _, _, _, _, _, _, _, _)
then
();
case (r::rest, _, _, _, _, _, _, _, _)
guard
not intEq(rowmarks[r], mark)
equation
// marked?
e = ass1[r];
rlst = ass2[e];
lst = List.fold1(rlst, List.removeOnTrue, intEq, m[e]);
(lst1 as _::_) = List.select2(lst, unmarked, rowmarks, mark-1);
// print("generateClique " + intString(eqn) + " to " + stringDelimitList(List.map(lst1, intString), ", ") + "\n");
List.map4_0(lst1, generateResidualClique, m, mt, orphan, e);
List.map2_0(rlst, doMark, rowmarks, mark);
lst = List.select2(lst, marked, rowmarks, mark-1);
// print("Go From " + intString(e) + " to " + stringDelimitList(List.map(r, intString), ", ") + "\n");
arrayUpdate(colummarks, e, mark);
// print("Go From " + intString(e) + " to " + stringDelimitList(List.map(next, intString), ", ") + "\n");
generateCliquesResidual2(lst, ass1, ass2, m, mt, mark, rowmarks, colummarks, orphan);
generateCliquesResidual2(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, orphan);
then
();
case (_::rest, _, _, _, _, _, _, _, _)
equation
generateCliquesResidual2(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, orphan);
then
();
end match;
end generateCliquesResidual2;
protected function prepairOrphansOrder "author: Frenkel TUD 2012-07"
input list<Integer> inOrphans;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input Integer mark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input array<list<Integer>> orphans;
input BackendDAE.Variables vars;
input list<Integer> iroots;
input list<Integer> iconstraints;
output Integer omark;
output list<Integer> oroots;
output list<Integer> oconstraints;
algorithm
(omark, oroots, oconstraints) := match(inOrphans, ass1, ass2, m, mt, mark, rowmarks, colummarks, orphans, vars, iroots, iconstraints)
local
list<Integer> rest, roots, constraints, elst, rlst;
Integer o;
Boolean foundflow, constr;
list<BackendDAE.Var> vlst;
case ({}, _, _, _, _, _, _, _, _, _, _, _)
then
(mark, iroots, iconstraints);
case (o::rest, _, _, _, _, _, _, _, _, _, _, _)
guard
not intEq(rowmarks[o], mark)
equation
arrayUpdate(rowmarks, o, mark);
elst = mt[o];
rlst = List.flatten(List.map1r(elst, arrayGet, ass2));
// check for partner
// BackendDump.debuglst((rlst, intString, ", ", "\n"));
vlst = List.map1r(rlst, BackendVariable.getVarAt, vars);
constr = List.mapBoolAnd(vlst, BackendVariable.isFlowVar);
constraints = List.consOnTrue(constr, o, iconstraints);
// print("Process Orphan " + intString(o) + "\n");
// BackendDump.debuglst((mt[o], intString, ", ", "\n"));
foundflow = prepairOrphansOrder1(mt[o], ass1, ass2, m, mt, mark, rowmarks, colummarks, o, orphans, {o}, false, vars);
roots = List.consOnTrue(foundflow and not constr, o, iroots);
(omark, roots, constraints) = prepairOrphansOrder(rest, ass1, ass2, m, mt, mark+1, rowmarks, colummarks, orphans, vars, roots, constraints);
then
(omark, roots, constraints);
case (_::rest, _, _, _, _, _, _, _, _, _, _, _)
equation
(omark, roots, constraints) = prepairOrphansOrder(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, orphans, vars, iroots, iconstraints);
then
(omark, roots, constraints);
end match;
end prepairOrphansOrder;
protected function prepairOrphansOrder1 "author: Frenkel TUD 2012-05"
input list<Integer> eqns;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input Integer mark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input Integer preorphan;
input array<list<Integer>> orphans;
input list<Integer> prer;
input Boolean ifoundFlow;
input BackendDAE.Variables vars;
output Boolean ofoundFlow = ifoundFlow;
protected
list<Integer> next, r, elst;
Boolean b1;
list<Boolean> blst;
list<BackendDAE.Var> vlst;
algorithm
for e in eqns loop
if not intEq(colummarks[e], mark) then
// remove orphans
next := List.select1(m[e], isNoOrphan, ass1);
// remove visited
next := List.select2(next, unmarked, rowmarks, mark);
// remove assigned
next := List.fold1(ass2[e], List.removeOnTrue, intEq, next);
if listEmpty(next) then
arrayUpdate(colummarks, e, mark);
r := ass2[e];
// print("Go From " + intString(e) + " to " + stringDelimitList(List.map(r, intString), ", ") + "\n");
List.map2_0(r, doMark, rowmarks, mark);
elst := List.select1(List.map1r(r, arrayGet, ass1), intGt, 0);
next := List.flatten(List.map1r(r, arrayGet, mt));
next := List.fold1(elst, List.removeOnTrue, intEq, next);
List.map2_0(r, addPreOrphan, preorphan, orphans);
vlst := List.map1r(r, BackendVariable.getVarAt, vars);
blst := List.map(vlst, BackendVariable.isFlowVar);
b1 := Util.boolOrList(blst);
// print("Go From " + intString(e) + " to " + stringDelimitList(List.map(next, intString), ", ") + "\n");
ofoundFlow := prepairOrphansOrder1(next, ass1, ass2, m, mt, mark, rowmarks, colummarks, preorphan, orphans, r, b1 or ofoundFlow, vars);
end if;
end if;
end for;
end prepairOrphansOrder1;
protected function prepairOrphansOrder2 "author: Frenkel TUD 2012-07"
input list<Integer> inOrphans;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input Integer imark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input array<list<Integer>> orphans;
output Integer omark;
algorithm
omark := matchcontinue(inOrphans, ass1, ass2, m, mt, imark, rowmarks, colummarks, orphans)
local
list<Integer> rest, elst, rlst, partner;
Integer o;
case ({}, _, _, _, _, _, _, _, _)
then
imark+1;
case (o::rest, _, _, _, _, _, _, _, _)
equation
false = intEq(rowmarks[o], imark);
arrayUpdate(rowmarks, o, imark);
// print("Process Orphan " + intString(o) + "\n");
// BackendDump.debuglst((mt[o], intString, ", ", "\n"));
// check for partner
elst = List.select1(mt[o], intGt, 0) "eqns of orphan";
rlst = List.select1(List.flatten(List.map1r(elst, arrayGet, m)), intGt, 0);
partner = List.select1(rlst, isOrphan, ass1);
partner = List.unique(partner);
List.map2_0(partner, doMark, rowmarks, imark);
// print("Found for " + intString(o) + " Parnters: " + stringDelimitList(List.map(partner, intString), ", ") + "\n");
prepairOrphansOrder3(mt[o], ass1, ass2, m, mt, imark, rowmarks, colummarks, o, partner, orphans, {o});
then
prepairOrphansOrder2(rest, ass1, ass2, m, mt, imark, rowmarks, colummarks, orphans);
case (_::rest, _, _, _, _, _, _, _, _)
then
prepairOrphansOrder2(rest, ass1, ass2, m, mt, imark, rowmarks, colummarks, orphans);
end matchcontinue;
end prepairOrphansOrder2;
protected function prepairOrphansOrder3 "author: Frenkel TUD 2012-05"
input list<Integer> eqns;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input Integer mark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input Integer preorphan;
input list<Integer> partner;
input array<list<Integer>> orphans;
input list<Integer> prer;
algorithm
_ := matchcontinue(eqns, ass1, ass2, m, mt, mark, rowmarks, colummarks, preorphan, partner, orphans, prer)
local
Integer e;
list<Integer> rest, next, r, elst, lst;
case ({}, _, _, _, _, _, _, _, _, _, _, _)
then
();
case (e::rest, _, _, _, _, _, _, _, _, _, _, _)
equation
false = intEq(colummarks[e], mark);
// marked?
r = ass2[e];
lst = List.unique(List.flatten(List.map1r(r, arrayGet, orphans)));
true = listMember(preorphan, lst);
arrayUpdate(colummarks, e, mark);
// print("Go From " + intString(e) + " to " + stringDelimitList(List.map(r, intString), ", ") + "\n");
List.map2_0(r, doMark, rowmarks, mark);
elst = List.select1(List.map1r(r, arrayGet, ass1), intGt, 0);
next = List.flatten(List.map1r(r, arrayGet, mt));
next = List.fold1(elst, List.removeOnTrue, intEq, next);
// print("Go From " + intString(e) + " to " + stringDelimitList(List.map(next, intString), ", ") + "\n");
prepairOrphansOrder3(next, ass1, ass2, m, mt, mark, rowmarks, colummarks, preorphan, partner, orphans, r);
prepairOrphansOrder3(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, preorphan, partner, orphans, prer);
then
();
case (e::rest, _, _, _, _, _, _, _, _, _, _, _)
equation
// print("check Eqn " + intString(e) + " ass[e]: " + stringDelimitList(List.map(ass2[e], intString), ", ") + "\n");
false = intEq(colummarks[e], mark);
// update Adjacency Matrix
List.map4_0(prer, generateClique, m, mt, partner, e);
prepairOrphansOrder3(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, preorphan, partner, orphans, prer);
then
();
case (_::rest, _, _, _, _, _, _, _, _, _, _, _)
equation
prepairOrphansOrder3(rest, ass1, ass2, m, mt, mark, rowmarks, colummarks, preorphan, partner, orphans, prer);
then
();
end matchcontinue;
end prepairOrphansOrder3;
protected function generateClique
input Integer r;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input list<Integer> orphans;
input Integer e;
algorithm
_:= match(r, m, mt, orphans, e)
local
Integer orphan;
list<Integer> lst, rest;
case (_, _, _, {}, _) then ();
case (_, _, _, orphan::rest, _)
equation
// print("Replace " + intString(r) + " with " + intString(orphan) + "\n");
lst = mt[r];
// mt[r]-e
lst = List.removeOnTrue(e, intEq, lst);
// print("mt[ " + intString(r) + "]= " + stringDelimitList(List.map(lst, intString), ", ") + "\n");
arrayUpdate(mt, r, lst);
// mt[preorphan]+e
lst = mt[orphan];
lst = List.unique(e::lst);
// print("mt[ " + intString(orphan) + "]= " + stringDelimitList(List.map(lst, intString), ", ") + "\n");
arrayUpdate(mt, orphan, lst);
// m[e] - r + preorphan
lst = m[e];
lst = List.removeOnTrue(r, intEq, lst);
lst = List.unique(orphan::lst);
// print("m[ " + intString(e) + "]= " + stringDelimitList(List.map(lst, intString), ", ") + "\n");
arrayUpdate(m, e, lst);
generateClique(r, m, mt, rest, e);
then
();
end match;
end generateClique;
protected function generateResidualClique
input Integer r;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input list<Integer> orphans;
input Integer e;
algorithm
_:= match(r, m, mt, orphans, e)
local
Integer orphan;
list<Integer> lst, rest;
case (_, _, _, {}, _) then ();
case (_, _, _, orphan::rest, _)
equation
// print("Replace " + intString(e) + " with " + intString(orphan) + "\n");
lst = m[e];
// mt[e]-r
lst = List.removeOnTrue(r, intEq, lst);
// print("m[ " + intString(e) + "]= " + stringDelimitList(List.map(lst, intString), ", ") + "\n");
arrayUpdate(m, e, lst);
// m[orphan]+r
lst = m[orphan];
lst = List.unique(r::lst);
// print("m[ " + intString(orphan) + "]= " + stringDelimitList(List.map(lst, intString), ", ") + "\n");
arrayUpdate(m, orphan, lst);
// mt[r] - e + orphan
lst = mt[r];
lst = List.removeOnTrue(e, intEq, lst);
lst = List.unique(orphan::lst);
// print("mt[ " + intString(r) + "]= " + stringDelimitList(List.map(lst, intString), ", ") + "\n");
arrayUpdate(mt, r, lst);
generateResidualClique(r, m, mt, rest, e);
then
();
end match;
end generateResidualClique;
protected function getOrphansOrderEdvanced "author: Frenkel TUD 2012-07"
input list<Integer> inOrphans;
input array<Integer> ass1;
input array<list<Integer>> ass2;
input BackendDAE.AdjacencyMatrix m;
input BackendDAE.AdjacencyMatrixT mt;
input BackendDAE.AdjacencyMatrix mc;
input BackendDAE.AdjacencyMatrixT mct;
input Integer mark;
input array<Integer> rowmarks;
input array<Integer> colummarks;
input array<list<Integer>> orphans;
output Integer omark;
algorithm
omark := matchcontinue(inOrphans, ass1, ass2, m, mt, mc, mct, mark, rowmarks, colummarks, orphans)
local
list<Integer> rest;
Integer o;
case ({}, _, _, _, _, _, _, _, _, _, _)
then
mark;
case (o::rest, _, _, _, _, _, _, _, _, _, _)
equation
false = intEq(rowmarks[o], mark);
arrayUpdate(rowmarks, o, mark);
// print("Process Orphan " + intString(o) + "\n");
getOrphansOrderEdvanced1(mct[o], ass1, ass2, m, mt, mark, rowmarks, colummarks, o, orphans, {});
then
getOrphansOrderEdvanced(rest, ass1, ass2, m, mt, mc, mct, mark+1, rowmarks, colummarks, orphans);
case (_::rest, _, _, _, _, _, _, _, _, _, _)
then
getOrphansOrderEdvanced(rest, ass1, ass2, m, mt, mc, mct, mark, rowmarks, colummarks, orphans);
end matchcontinue;