-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: commit ecfe8dd Author: Joaquin <[email protected]> Date: Mon Nov 16 18:05:50 2020 -0300 Fixed merge conflicts. commit 15d4e1b Author: Joaquin <[email protected]> Date: Mon Nov 16 17:57:15 2020 -0300 Merge new files, split vector graph implementation. commit 756b3e4 Author: Joaquin <[email protected]> Date: Mon Nov 16 14:56:17 2020 -0300 Vector graph implementation new files. commit e08f986 Author: Joaquin <[email protected]> Date: Thu Nov 12 18:58:39 2020 -0300 Change std compile flags.
- Loading branch information
1 parent
366abbe
commit ad8dd38
Showing
121 changed files
with
7,587 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include causalize/graph_implementation/Makefile.include | ||
include causalize/vg_implementation/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
all: bin/vg_causalize | ||
SRC_VG_CAUSALIZE := causalize/vg_implementation/main.cpp \ | ||
causalize/vg_implementation/apply_tarjan.cpp \ | ||
causalize/vg_implementation/unknowns_collector.cpp \ | ||
causalize/vg_implementation/causalization_strategy.cpp \ | ||
causalize/vg_implementation/vector/graph_builder.cpp \ | ||
causalize/vg_implementation/vector/causalization_algorithm.cpp \ | ||
causalize/vg_implementation/vector/splitfor.cpp \ | ||
causalize/vg_implementation/vector/vector_graph_definition.cpp \ | ||
causalize/vg_implementation/vector/vector_tarjan.cpp \ | ||
causalize/vg_implementation/vector/vector_matching.cpp \ | ||
causalize/vg_implementation/graph/graph_definition.cpp \ | ||
causalize/vg_implementation/for_unrolling/process_for_equations.cpp \ | ||
causalize/common/for_unrolling/for_index_iterator.cpp \ | ||
util/debug.cpp \ | ||
util/table.cpp \ | ||
util/type.cpp \ | ||
util/solve/solve.cpp \ | ||
util/ast_visitors/contains_unknown.cpp \ | ||
util/ast_visitors/contains_vector.cpp \ | ||
util/ast_visitors/eval_expression.cpp \ | ||
util/ast_visitors/partial_eval_expression.cpp \ | ||
util/ast_visitors/ginac_interface.cpp \ | ||
util/ast_visitors/contains_expression.cpp \ | ||
util/ast_visitors/splitfor_visitor.cpp \ | ||
util/ast_visitors/state_variables_finder.cpp \ | ||
mmo/mmo_class.cpp | ||
|
||
|
||
OBJS_VG_CAUSALIZE = $(SRC_VG_CAUSALIZE:.cpp=.o) | ||
-include $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRC_CAUSALIZE))) | ||
LIB_CAUSALIZE = -L./lib -lmodelica -lginac | ||
|
||
bin/vg_causalize: $(OBJS_VG_CAUSALIZE) lib/libmodelica.a | ||
$(CXX) $(CXXFLAGS) -o bin/vg_causalize $(OBJS_VG_CAUSALIZE) $(LIB_CAUSALIZE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/***************************************************************************** | ||
This file is part of Modelica C Compiler. | ||
Modelica C Compiler is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Modelica C Compiler is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Modelica C Compiler. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include <causalize/vg_implementation/apply_tarjan.h> | ||
#include <util/debug.h> | ||
|
||
#include <boost/property_map/property_map.hpp> | ||
#include <boost/graph/max_cardinality_matching.hpp> | ||
#include <boost/graph/strong_components.hpp> | ||
#include <boost/graph/adjacency_list.hpp> | ||
|
||
#include <map> | ||
#include <stdio.h> | ||
|
||
namespace Causalize { | ||
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> DirectedGraph; | ||
typedef boost::graph_traits<DirectedGraph>::vertex_descriptor DGVertex; | ||
typedef boost::graph_traits<DirectedGraph>::edge_descriptor DGEdge; | ||
|
||
std::map<Vertex, Vertex> _matching; | ||
std::map<DGVertex, Vertex> _collapsed2original; | ||
using namespace Causalize; | ||
|
||
DGVertex original2collapsed(Vertex value) | ||
{ | ||
std::map<DGVertex, Vertex>::iterator it; | ||
for (it = _collapsed2original.begin(); it != _collapsed2original.end(); it++) { | ||
if ((*it).second == value) { | ||
return (*it).first; | ||
} | ||
} | ||
ERROR("Can't find collapsed vertex from original."); | ||
return (*it).first; | ||
} | ||
|
||
void buildCollapsedGraph(Causalize::CausalizationGraph &graph, DirectedGraph &digraph) | ||
{ | ||
// Create the vertices on the directed graph | ||
Causalize::CausalizationGraph::vertex_iterator vi, vi_end; | ||
for (boost::tie(vi, vi_end) = vertices(graph); vi != vi_end; ++vi) { | ||
if (graph[*vi].type == kVertexEquation) { | ||
DGVertex v = add_vertex(digraph); | ||
_collapsed2original[v] = *vi; | ||
} | ||
} | ||
// Create the edges on the directed graph | ||
DirectedGraph::vertex_iterator vj, vj_end; | ||
for (boost::tie(vj, vj_end) = vertices(digraph); vj != vj_end; ++vj) { | ||
CausalizationGraph::out_edge_iterator ek, ek_end; | ||
Vertex originalEqVertex = _collapsed2original[*vj]; | ||
Vertex uMatchingVertex = _matching[originalEqVertex]; | ||
for (boost::tie(ek, ek_end) = out_edges(uMatchingVertex, graph); ek != ek_end; ++ek) { | ||
Vertex eqAdjacentVertex = target(*ek, graph); | ||
if (eqAdjacentVertex != originalEqVertex) { | ||
boost::add_edge(original2collapsed(eqAdjacentVertex), *vj, digraph); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// void replaceMMOClassEquations(MMO_Class mmoClass, MMO_EquationList causalEqs) { | ||
// MMO_EquationList oldEquations = mmoClass->getEquations(); | ||
// MMO_EquationListIterator iter, auxiliaryIter; | ||
// auxiliaryIter = oldEquations->begin(); | ||
// for(iter = auxiliaryIter; iter != oldEquations->end(); iter = auxiliaryIter) { | ||
// ++auxiliaryIter; | ||
// mmoClass->removeEquation(current_element(iter)); | ||
// } | ||
// foreach(iter, causalEqs) { | ||
// mmoClass->addEquation(current_element(iter)); | ||
// } | ||
//} | ||
|
||
int apply_tarjan(CausalizationGraph &graph, std::map<int, Causalize::ComponentPtr> &components) | ||
{ | ||
boost::associative_property_map<std::map<Vertex, Vertex>> matching_map(_matching); | ||
|
||
// Vertex Index Map required for checked_edmonds_maximum_cardinality_matching. | ||
// This is to allow the causalization graph, which is an adjacency list, to | ||
// use as VertexList either vecS or listS. | ||
std::map<Vertex, int> vertex2index; | ||
CausalizationGraph::vertex_iterator i, iend; | ||
int ic = 0; | ||
for (boost::tie(i, iend) = vertices(graph); i != iend; ++i, ++ic) { | ||
vertex2index[*i] = ic; | ||
} | ||
boost::associative_property_map<std::map<Vertex, int>> index_map(vertex2index); | ||
|
||
DEBUG('c', "Calculating maximum cardinality matching over causalization graph...\n"); | ||
|
||
bool success = checked_edmonds_maximum_cardinality_matching(graph, matching_map, index_map); | ||
if (!success) { | ||
ERROR("Can't find a maximum cardinality matching.\n"); | ||
} | ||
|
||
for (std::map<Vertex, Vertex>::iterator it = _matching.begin(); it != _matching.end(); ++it) { | ||
char se[10]; | ||
Vertex v1 = it->first; | ||
if (graph[v1].type == kVertexEquation) { | ||
sprintf(se, "E%d", vertex2index[v1]); | ||
} else { | ||
sprintf(se, "U%d", vertex2index[v1]); | ||
} | ||
char su[10]; | ||
Vertex v2 = it->second; | ||
if (graph[v2].type == kVertexEquation) { | ||
sprintf(su, "E%d", vertex2index[v2]); | ||
} else { | ||
sprintf(su, "U%d", vertex2index[v2]); | ||
} | ||
DEBUG('c', "%s matches %s\n", se, su); | ||
} | ||
|
||
DirectedGraph collapsedGraph; | ||
|
||
DEBUG('c', "Collapsing matching vertices...\n"); | ||
|
||
buildCollapsedGraph(graph, collapsedGraph); | ||
|
||
std::map<DGVertex, int> vertex2component; | ||
boost::associative_property_map<std::map<DGVertex, int>> component_map(vertex2component); | ||
std::map<DGVertex, int> dg_vertex2index; | ||
DirectedGraph::vertex_iterator j, jend; | ||
int jc = 0; | ||
for (boost::tie(j, jend) = vertices(collapsedGraph); j != jend; ++j, ++jc) { | ||
dg_vertex2index[*j] = jc; | ||
} | ||
boost::associative_property_map<std::map<DGVertex, int>> dg_index_map(dg_vertex2index); | ||
|
||
DEBUG('c', "Running tarjan algorithm over collapsed graph...\n"); | ||
|
||
int numComponents = strong_components(collapsedGraph, component_map, boost::vertex_index_map(dg_index_map)); | ||
|
||
DEBUG('c', "%d strong components identifed.\n", numComponents); | ||
|
||
for (std::map<DGVertex, int>::iterator it = vertex2component.begin(); it != vertex2component.end(); ++it) { | ||
DGVertex dgVertex = it->first; | ||
int componentIndex = it->second; | ||
DEBUG('c', "Vertex: %d -- Component: %d\n", dg_vertex2index[dgVertex], componentIndex); | ||
Vertex eqVertex = _collapsed2original[dgVertex]; | ||
Vertex uVertex = _matching[eqVertex]; | ||
std::map<int, Causalize::ComponentPtr>::iterator componentsIt = components.find(componentIndex); | ||
if (componentsIt == components.end()) { | ||
Causalize::ComponentPtr component = new Causalize::Component; | ||
std::list<Vertex> *uVertices = new std::list<Vertex>; | ||
uVertices->push_back(uVertex); | ||
component->uVertices = uVertices; | ||
std::list<Vertex> *eqVertices = new std::list<Vertex>; | ||
eqVertices->push_back(eqVertex); | ||
component->eqVertices = eqVertices; | ||
components[componentIndex] = component; | ||
} else { | ||
Causalize::ComponentPtr component = componentsIt->second; | ||
std::list<Vertex> *uVertices = component->uVertices; | ||
uVertices->push_back(uVertex); | ||
std::list<Vertex> *eqVertices = component->eqVertices; | ||
eqVertices->push_back(eqVertex); | ||
} | ||
} | ||
|
||
return components.size(); | ||
} | ||
|
||
} // namespace Causalize |
Oops, something went wrong.