CIFASIS / modelicacc

Modelica C Compiler implemented in C++ to develop and test novel algorithms for large scale models.
GNU General Public License v3.0
11 stars 9 forks source link

Connected components algorithm #45

Closed Kalashnikovni closed 3 years ago

Kalashnikovni commented 3 years ago

Given the graph described by the set-vertices, and set-edges:

Cell_r: {{[1:1:1]x[1:1:1]}}
Cell_l: {{[2:1:2]x[2:1:2]}}
Cell_d: {{[3:1:3]x[3:1:3]}}
Cell_u: {{[4:1:4]x[4:1:4]}}
S_p: {{[5:1:5]x[5:1:5]}}
S_n: {{[6:1:6]x[6:1:6]}}
Cell_resistor_n: {{[7:1:7]x[7:1:7]}}
Cell_capacitor_p: {{[8:1:8]x[8:1:8]}}
Cell_resistor1_n: {{[9:1:9]x[9:1:9]}}
Cell_capacitor1_p: {{[10:1:10]x[10:1:10]}}
Cell_resistor_p: {{[11:1:11]x[11:1:11]}}
Cell_capacitor_n: {{[12:1:12]x[12:1:12]}}
Cell_resistor1_p: {{[13:1:13]x[13:1:13]}}
Cell_capacitor1_n: {{[14:1:14]x[14:1:14]}}
G_p: {{[15:1:15]x[15:1:15]}}
E_Cell_l_Cell_r: [({{[0:1:0]x[0:1:0]}}, [0 * x + 1, 0 * x + 1])], [({{[0:1:0]x[0:1:0]}}, [0 * x + 2, 0 * x + 2])]
E_Cell_u_S_p: [({{[1:1:1]x[1:1:1]}}, [0 * x + 4, 0 * x + 4])], [({{[1:1:1]x[1:1:1]}}, [0 * x + 5, 0 * x + 5])]
E_Cell_d_S_n: [({{[2:1:2]x[2:1:2]}}, [0 * x + 3, 0 * x + 3])], [({{[2:1:2]x[2:1:2]}}, [0 * x + 6, 0 * x + 6])]
E_Cell_capacitor_p_Cell_resistor_n: [({{[3:1:3]x[3:1:3]}}, [0 * x + 7, 0 * x + 7])], [({{[3:1:3]x[3:1:3]}}, [0 * x + 8, 0 * x + 8])]
E_Cell_capacitor1_p_Cell_resistor1_n: [({{[4:1:4]x[4:1:4]}}, [0 * x + 9, 0 * x + 9])], [({{[4:1:4]x[4:1:4]}}, [0 * x + 10, 0 * x + 10])]
E_Cell_capacitor_p_Cell_resistor1_n: [({{[5:1:5]x[5:1:5]}}, [0 * x + 9, 0 * x + 9])], [({{[5:1:5]x[5:1:5]}}, [0 * x + 8, 0 * x + 8])]
E_Cell_l_Cell_resistor_p: [({{[6:1:6]x[6:1:6]}}, [0 * x + 2, 0 * x + 2])], [({{[6:1:6]x[6:1:6]}}, [0 * x + 11, 0 * x + 11])]
E_Cell_capacitor_n_Cell_r: [({{[7:1:7]x[7:1:7]}}, [0 * x + 12, 0 * x + 12])], [({{[7:1:7]x[7:1:7]}}, [0 * x + 1, 0 * x + 1])]
E_Cell_resistor1_p_Cell_u: [({{[8:1:8]x[8:1:8]}}, [0 * x + 13, 0 * x + 13])], [({{[8:1:8]x[8:1:8]}}, [0 * x + 4, 0 * x + 4])]
E_Cell_capacitor1_n_Cell_d: [({{[9:1:9]x[9:1:9]}}, [0 * x + 14, 0 * x + 14])], [({{[9:1:9]x[9:1:9]}}, [0 * x + 3, 0 * x + 3])]

Generated Connect Graph written to network2D.dot

The result of applying connectedComponents is:

Connected components of SBG: network2D.dot
[({{[15:1:15]x[15:1:15]}}, [1 * x + 0, 1 * x + 0]) , ({{[1:1:1]x[1:1:1]}}, [1 * x + 0, 1 * x + 0]), ({{[12:1:12]x[12:1:12]}}, [0 * x + 1, 0 * x + 1]), ({{[3:1:3]x[3:1:3]}}, [0 * x + 3, 0 * x + 3]), ({{[4:1:4]x[4:1:4]}}, [0 * x + 4, 0 * x + 4]), ({{[11:1:11]x[11:1:11]}}, [0 * x + 2, 0 * x + 2]), ({{[2:1:2]x[2:1:2]}}, [1 * x + 0, 1 * x + 0]), ({{[10:1:10]x[10:1:10]}}, [0 * x + 7, 0 * x + 7]), ({{[9:1:9]x[9:1:9]}}, [0 * x + 7, 0 * x + 7]), ({{[8:1:8]x[8:1:8]}}, [0 * x + 7, 0 * x + 7]), ({{[7:1:7]x[7:1:7]}}, [1 * x + 0, 1 * x + 0]), ({{[6:1:6]x[6:1:6]}}, [0 * x + 6, 0 * x + 6]), ({{[14:1:14]x[14:1:14]}}, [0 * x + 6, 0 * x + 6]), ({{[5:1:5]x[5:1:5]}}, [0 * x + 5, 0 * x + 5]), ({{[13:1:13]x[13:1:13]}}, [0 * x + 5, 0 * x + 5])]

The result is not correct, as, for example, [2:1:2]x[2:1:2] should be represented by [1:1:1]x[1:1:1], as the set-edge E_Cell_l_Cell_r exists.

Kalashnikovni commented 3 years ago

Fixing the following error:

denise@statechart:~/Materias/Doctorado/modelicacc$ make
cc -I. -std=c++14 -Wall -Werror -Wno-reorder -O3  -ggdb   -MM -MT obj/debug/flatter/connectors.o -MF obj/debug/flatter/connectors.d flatter/connectors.cpp
cc -I. -c flatter/connectors.cpp -o obj/debug/flatter/connectors.o -std=c++14 -Wall -Werror -Wno-reorder -O3  -ggdb  
flatter/connectors.cpp: In member function ‘Modelica::AST::EquationList Connectors::buildLoop(Modelica::AST::Indexes, Modelica::AST::EquationList)’:
flatter/connectors.cpp:1530:9: error: ‘ContainsExpressionFlatter’ was not declared in this scope
 1530 |         ContainsExpressionFlatter co(ei);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ./flatter/connectors.h:23,
                 from flatter/connectors.cpp:18:
flatter/connectors.cpp:1533:19: error: ‘co’ was not declared in this scope; did you mean ‘cos’?
 1533 |         if (Apply(co, left) || Apply(co, right)) {
      |                   ^~
./ast/ast_types.h:104:42: note: in definition of macro ‘Apply’
  104 | #define Apply(X, Y) boost::apply_visitor(X, Y)
      |                                          ^
make: *** [Makefile:58: obj/debug/flatter/connectors.o] Error 1