PowerCircuitCompMatrix.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef POWERCIRCUITCOMPMATRIX_H_
00009 #define POWERCIRCUITCOMPMATRIX_H_
00010
00011 namespace PC
00012 {
00013
00014 class PowerCircuitCompMatrix : public PowerCircuit
00015 {
00016 private:
00017
00018
00019 struct RowHdr
00020 {
00021 Marking lambdaMarking;
00022 bool BV;
00023 unsigned int indexInNodes;
00024
00025 RowHdr() {}
00026 RowHdr(const Marking& l, bool bv, int i): lambdaMarking(l), BV(bv), indexInNodes(i) {}
00027 };
00028
00029 struct ColHdr
00030 {
00031 std::list<Marking> markings;
00032 };
00033
00034
00035 SignMatrix<RowHdr,ColHdr,unsigned int> matrix;
00036 unsigned int numTreedCols;
00037 unsigned int numTreedNodes;
00038
00039
00040
00041
00042 enum MarkingType
00043 {
00044 NORMAL,LAMBDA
00045 };
00046
00047 struct IntNode
00048 {
00049 Row row;
00050 PowerCircuitCompMatrix* pc;
00051 bool deleted;
00052 int nextDeleted;
00053 };
00054
00055 struct IntMarking
00056 {
00057 Col col;
00058 PowerCircuitCompMatrix* pc;
00059 MarkingType type;
00060 Row node;
00061 bool deleted;
00062 int nextDeleted;
00063 };
00064
00065 typedef std::vector<IntMarking> MarkingVector;
00066 typedef std::vector<IntNode> NodeVector;
00067
00068 static MarkingVector markings;
00069 static NodeVector nodes;
00070 static unsigned int totalNumMarkings;
00071 static unsigned int totalNumNodes;
00072 static int firstDeletedMarking;
00073 static int firstDeletedNode;
00074
00075
00076
00077 bool checkMarkingValid(const Marking& m) const;
00078 bool checkNodeValid(Node n) const;
00079
00080 void deleteNode(Row node);
00081 void deleteCol(Col col);
00082 void deleteMarking(Marking& mark);
00083
00084 Marking allocateNewMarking(Col col);
00085 Row newNodeFromMarking(const Marking& mark);
00086
00087 Row newOneNode();
00088 Row cloneNode(Row node);
00089
00090 Marking newOneMarking();
00091 Marking newZeroMarking();
00092 Marking newUnitMarking(int onePos);
00093 Marking newCopyColMarking(const Marking& mark);
00094
00095 void separateMarkingFromCol(const Marking& m);
00096 void mergeCols(Col targetCol, Col col2);
00097 int getTreedNodePosToGivenCol(Col col);
00098 void moveNodeIntoTreedPartOfMatrix(Row node, int newPos);
00099
00100 int findNewPosOfCompactCol(Col col, bool& equal);
00101
00102 void compactifyFromBottom(Col col);
00103 void insertNewPowerOfTwoNode(unsigned int power);
00104 unsigned int calculateCompactRepresentation(int n, Sign result[32]);
00105
00106 void setBV(Row node);
00107 void newDoubleNode(Row node);
00108 void compactify(Col col);
00109
00110 void removeDoubleNodesFromMarkings(Row oldNode, Row newNode);
00111 int insertCompactMarkingIntoTreed(const Marking& mark) ;
00112 int insertCompactColIntoTreed(Col col) ;
00113
00114 int insertNodeIntoTreed(Row node);
00115 void moveColsToTreed(std::list<Col>& colList);
00116 void topSortNode(unsigned int nodeIndex, std::vector<Row>& nodesToSort, std::vector<bool>& visited, std::vector<Row>& topSortPerm);
00117
00118 void extendTree(std::vector<Row>& nodeList, std::vector<Col>& colList);
00119
00120 void checkCyclesRecursive(Row node, std::vector<bool> visited);
00121 void checkCycles();
00122
00123
00124
00125
00126
00127 virtual void incMarkingRefCount(const Marking& mark);
00128 virtual void decMarkingRefCount(Marking& mark);
00129
00130 virtual Marking addMarkings(const Marking& m1, const Marking& m2) ;
00131 virtual Marking invMarking(const Marking& m);
00132 virtual Marking incMarking(const Marking& mark);
00133 virtual Marking intersectMarkings(const Marking& m1, const Marking& m2);
00134 virtual Marking cloneMarking(const Marking& mark);
00135 virtual Node cloneNode(Node n);
00136 virtual Marking copyMarking(const Marking& m);
00137 virtual bool isMarkingReduced(const Marking& m) const;
00138 virtual int compareMarkings(const Marking& m1, const Marking& m2);
00139 virtual int getRedNodeOrd(Node n);
00140 virtual int getNodeSignInMarking(Node n, const Marking& m) const;
00141 virtual bool isSuccessorMarking(const Marking& m) const;
00142 virtual Node getIncidentNode(const Marking& m);
00143 virtual Node getSmallestNodeInMarking(const Marking& m);
00144 virtual Marking getSuccMarking(Node n);
00145
00146 public:
00147
00148 PowerCircuitCompMatrix(int numInitNodes=0, int numInitCols=0);
00149 virtual ~PowerCircuitCompMatrix();
00150
00151
00152 virtual void reduce();
00153 virtual void reduce(std::vector<Node>& nodeVector, std::vector<Marking>& markingVector);
00154 virtual Marking createMarking(int i = 0);
00155 virtual Marking createMarking(const std::list<Node>& nodes);
00156 virtual Marking createMarking(const std::list<Node>& nodeList, const std::list<int>& signList);
00157 virtual Node createNode(const Marking& succ) ;
00158 virtual void connect(const Marking& m, const Marking& p) ;
00159 virtual void connectInv(const Marking& m, const Marking& q);
00160 virtual void remove(const Marking& m) ;
00161 virtual Node getReducedNode(unsigned int ord);
00162 virtual std::list<Node> getNodes();
00163 virtual std::list<Marking> getMarkings();
00164 virtual std::list<Node> getMarkingNodes(const Marking& m);
00165 virtual PowerCircuit* clone(std::vector<Marking>& markingsToKeep);
00166
00167
00168 virtual void print(std::ostream& os= std::cout);
00169 double getMatrixUsage();
00170 virtual void printStatistics(std::ostream& os = std::cout);
00171 };
00172
00173 }
00174
00175 #endif