1 #ifndef CELL_MAPPING_CPP_CSCM_H 2 #define CELL_MAPPING_CPP_CSCM_H 8 template <
class IDType>
12 std::vector<IDType> cells;
23 const std::vector<IDType> &cells,
25 IDType imageCell) : cmid(cmid), cells(cells), state(state), imageCell(imageCell) {
29 const std::vector<IDType> &cells,
30 const CellState &state) : cmid(cmid), cells(cells), state(state) {
34 CellTree::cmid = cmid;
36 void setCells(
const std::vector<IDType> &cells) {
37 CellTree::cells = cells;
40 CellTree::state = state;
55 CellTree::imageCell = imageCell;
61 CellTree::imageCmid = imageCmid;
65 template <
class CellType,
class IDType,
class StateVectorType>
70 std::vector<CellTree<IDType>> cellTrees;
74 std::vector<IDType>& sinkDoA1) {
83 IDType cmid1 = scm1p->
getCss().getCell(0).getClusterID();
84 IDType cmid2 = scm2p->
getCss().getCell(0).getClusterID();
85 IDType z; IDType imz; IDType cmidz;
86 std::vector<IDType> seq;
88 for(
size_t i=0; i<sinkDoA1.size(); i++) {
101 imz = scm1p->
getCss().getCell(z).getImage();
104 cmidz = scm1p->
getCss().getCell(imz).getClusterID();
105 if (cmidz == cmid1) {
111 size_t ct = scm1p->
getCss().getCell(imz).getCellTreeID();
113 for (
size_t k = 0; k < seq.size(); k++) {
118 scm1p->
getCss().getCell(seq[k]).setCellTreeID(ct);
121 std::vector<IDType> cpcells = cellTrees[ct].getCells();
122 for (
size_t w=0; w<cpcells.size(); w++) {
123 seq.push_back(cpcells[w]);
127 cellTrees[ct].setCells(seq);
131 size_t otherG = scm1p->
getCss().getCell(imz).getGroup();
132 size_t otherCmid = scm1p->
getCss().getCell(imz).getClusterID();
133 for (
size_t k = 0; k < seq.size(); k++) {
134 scm1p->
getCss().getCell(seq[k]).setClusterID(otherCmid);
135 scm1p->
getCss().getCell(seq[k]).setGroup(otherG);
147 size_t otherG = scm1p->
getCss().getCell(imz).getGroup();
148 size_t otherCmid = scm1p->
getCss().getCell(imz).getClusterID();
149 for (
size_t k = 0; k < seq.size(); k++) {
150 scm1p->
getCss().getCell(seq[k]).setClusterID(otherCmid);
151 scm1p->
getCss().getCell(seq[k]).setGroup(otherG);
160 StateVectorType center = systemp->
step(scm1p->
getCss().getCenter(z));
161 imz = scm2p->
getCss().getID(center);
164 size_t otherG = scm2p->
getCss().getCell(imz).getGroup();
167 for (
size_t k = 0; k < seq.size(); k++) {
168 scm1p->
getCss().getCell(seq[k]).setClusterID(cmid2);
169 scm1p->
getCss().getCell(seq[k]).setGroup(otherG);
175 size_t ctIndex = cellTrees.size();
176 for (
size_t k = 0; k < seq.size(); k++) {
181 scm1p->
getCss().getCell(seq[k]).setCellTreeID(ctIndex);
189 cellTrees.push_back(cellTree);
193 for (
size_t k = 0; k < seq.size(); k++) {
205 IDType cmid1 = scm1p->
getCss().getCell(0).getClusterID();
206 IDType cmid2 = scm2p->
getCss().getCell(0).getClusterID();
210 for (
size_t i=0; i<cellTrees.size(); i++) {
218 std::vector<size_t> cycle;
223 bool processing =
true;
226 size_t cpImageCell = cellTrees[cpImage].getImageCell();
227 size_t cpImageCmid = cellTrees[cpImage].getImageCmid();
229 size_t imageCellGroup;
231 if (cpImageCmid == cmid1) {
232 imageCellState = scm1->
getCss().getCell(cpImageCell).getState();
233 imageCellGroup = scm1->
getCss().getCell(cpImageCell).getGroup();
235 imageCellState = scm2->
getCss().getCell(cpImageCell).getState();
236 imageCellGroup = scm2->
getCss().getCell(cpImageCell).getGroup();
241 for (
size_t k=0; k<cycle.size(); k++) {
243 std::vector<IDType> cellsk = cellTrees[cycle[k]].getCells();
244 if(cellTrees[cycle[k]].getClusterID() == cmid1) {
245 for (
size_t ck=0; ck<cellsk.size(); ck++) {
246 scm1->
getCss().getCell(cellsk[ck]).setGroup(imageCellGroup);
248 scm1->
getCss().getCell(cellsk[ck]).setClusterID(cmid1);
251 for (
size_t ck=0; ck<cellsk.size(); ck++) {
252 scm2->
getCss().getCell(cellsk[ck]).setGroup(imageCellGroup);
254 scm2->
getCss().getCell(cellsk[ck]).setClusterID(cmid1);
264 cpImageState = cellTrees[cpImage].getState();
268 cycle.push_back(cpImage);
272 size_t imageGroup = 1;
275 for (
size_t k=0; k<cycle.size(); k++) {
277 std::vector<IDType> cellsk = cellTrees[cycle[k]].getCells();
278 if(cellTrees[cycle[k]].getClusterID() == cmid1) {
279 for (
size_t ck=0; ck<cellsk.size(); ck++) {
280 scm1->
getCss().getCell(cellsk[ck]).setGroup(imageGroup);
284 for (
size_t ck=0; ck<cellsk.size(); ck++) {
285 scm2->
getCss().getCell(cellsk[ck]).setGroup(imageGroup);
298 for (
size_t k=0; k<cycle.size(); k++) {
300 std::vector<IDType> cellsk = cellTrees[cycle[k]].getCells();
301 if(cellTrees[cycle[k]].getClusterID() == cmid1) {
302 for (
size_t ck=0; ck<cellsk.size(); ck++) {
303 scm1->
getCss().getCell(cellsk[ck]).setGroup(newGroup);
305 scm1->
getCss().getCell(cellsk[ck]).setClusterID(cmid1);
308 for (
size_t ck=0; ck<cellsk.size(); ck++) {
309 scm2->
getCss().getCell(cellsk[ck]).setGroup(newGroup);
311 scm2->
getCss().getCell(cellsk[ck]).setClusterID(cmid1);
321 std::cout <<
"ERROR: CellTree with UNDER_PROCESSING state found!\n";
329 ClusteredSCM::scm1 = scm1p;
330 ClusteredSCM::scm2 = scm2p;
336 IDType cellPathImageCell = cellPaths[cellPathId].getImageCell();
337 IDType cellPathImageCmid = cellPaths[cellPathId].getImageCmid();
339 IDType targetCellPath = cellPaths.size();
340 std::vector<IDType> cells;
341 for (IDType cp = 0; cp < cellPaths.size(); cp++) {
342 if (cellPaths[cp].getClusterID() == cellPathImageCmid) {
343 cells = cellPaths[cp].getCells();
344 for (IDType cpc = 0; cpc < cells.size(); cpc++) {
345 if (cells[cpc] == cellPathImageCell) {
351 if (targetCellPath != cellPaths.size()) {
break; }
353 if(targetCellPath == cellPaths.size()) {
356 return targetCellPath;
361 void join(
bool verbose =
false) {
366 std::vector<IDType> sinkDoA1;
367 std::vector<IDType> sinkDoA2;
368 if (verbose) std::cout <<
"\nInitialization: " << std::endl;
369 size_t scm1count = scm1->
getCss().getCellSum();
370 size_t scm2count = scm2->
getCss().getCellSum();
371 IDType cmid1 = scm1->
getCss().getCell(0).getClusterID();
372 IDType cmid2 = scm2->
getCss().getCell(0).getClusterID();
374 if (cmid2 == cmid1) {
376 #pragma omp parallel for 377 for(
size_t i=0; i<scm2count; i++) {
378 scm2->
getCss().getCell(i).setClusterID(cmid2);
383 for(
size_t i=1; i<scm1count; i++) {
384 if (scm1->
getCss().getCell(i).getGroup() == 0) {
385 sinkDoA1.push_back(i);
389 for(
size_t i=1; i<scm2count; i++) {
390 if (scm2->
getCss().getCell(i).getGroup() == 0) {
391 sinkDoA2.push_back(i);
396 size_t sinkCount = sinkDoA1.size() + sinkDoA2.size();
398 std::cout <<
" SCM1's sink cell DoA contains: " << sinkDoA1.size() <<
" cells." << std::endl;
399 std::cout <<
" SCM2's sink cell DoA contains: " << sinkDoA2.size() <<
" cells." << std::endl;
400 std::cout <<
" Total number of cells in the joining procedure: " << sinkCount << std::endl;
403 std::cout <<
"\nStage 1:" << std::endl;
407 join_stage1(systemp, scm1, scm2, sinkDoA1);
408 join_stage1(systemp, scm2, scm1, sinkDoA2);
410 IDType cellStates[3];
415 for (IDType i = 0; i < sinkDoA1.size(); i++) {
416 cellStates[(int) scm1->
getCss().getCell(sinkDoA1[i]).getState()]++;
418 for (IDType i = 0; i < sinkDoA2.size(); i++) {
419 cellStates[(int) scm2->
getCss().getCell(sinkDoA2[i]).getState()]++;
427 std::cout << double(cellStates[(
int)
CellState::Processed])/sinkCount*100.0 <<
"%)" << std::endl;
431 for (IDType p=0; p < cellTrees.size(); p++) {
433 pathsum += cellTrees[p].getCells().size();
437 std::cout <<
" Cell trees constructed: " << cellTrees.size() << std::endl;
438 std::cout <<
" Number of cells in cell trees: " << pathsum << std::endl;
441 std::cout <<
"\nStage 2:" << std::endl;
444 join_stage2(scm1, scm2);
450 for (
size_t i = 0; i < sinkDoA1.size(); i++) {
451 cellStates[(int) scm1->
getCss().getCell(sinkDoA1[i]).getState()]++;
453 for (
size_t i = 0; i < sinkDoA2.size(); i++) {
454 cellStates[(int) scm2->
getCss().getCell(sinkDoA2[i]).getState()]++;
456 size_t processedPaths = 0;
457 for (
size_t p=0; p < cellTrees.size(); p++) {
466 std::cout << double(cellStates[(
int)
CellState::Processed])/sinkCount*100.0 <<
"%)" << std::endl;
467 std::cout <<
" Processed cell trees: " << processedPaths << std::endl;
475 #pragma omp parallel for 476 for (IDType z=1; z<scm1->
getCss().getCellSum(); z++) {
477 if (scm1->
getCss().getCell(z).getClusterID() == cmid2 && scm1->
getCss().getCell(z).getGroup() != 0) {
478 scm1->
getCss().getCell(z).setGroup(scm1->
getCss().getCell(z).getGroup()+groupshift);
481 #pragma omp parallel for 482 for (IDType z=1; z<scm2->
getCss().getCellSum(); z++) {
483 if (scm2->
getCss().getCell(z).getClusterID() == cmid2 && scm2->
getCss().getCell(z).getGroup() != 0) {
484 scm2->
getCss().getCell(z).setGroup(scm2->
getCss().getCell(z).getGroup()+groupshift);
497 #endif //CELL_MAPPING_CPP_CSCM_H CellTree()
Definition: cscm.h:17
Definition: coloring.h:50
void generateImage(std::string filepath, SCMColoringMethod< CellType, IDType > *coloringMethod=nullptr, IDType x0=0, IDType y0=0, IDType xw=0, IDType yw=0)
Definition: scm.h:123
CellState
Used during cell mapping algorithms.
Definition: cell.h:11
const CellState & getState() const
Definition: cscm.h:48
size_t cellPathImage(std::vector< CellTree< IDType >> &cellPaths, size_t cellPathId)
Finds the index of the image of a CellTree within the container cellPaths.
Definition: cscm.h:335
void setImageCmid(IDType imageCmid)
Definition: cscm.h:60
DynamicalSystemBase< StateVectorType > * getSystemPointer() const
Definition: scm.h:179
virtual StateVectorType step(const StateVectorType &state) const =0
const std::vector< IDType > & getCells() const
Definition: cscm.h:45
void setImageCell(IDType imageCell)
Definition: cscm.h:54
void setPeriodicGroups(IDType periodicGroups)
Definition: scm.h:191
void setClusterID(IDType cmid)
Definition: cscm.h:33
IDType getImageCmid() const
Definition: cscm.h:57
CellTree(IDType cmid, const std::vector< IDType > &cells, const CellState &state)
Definition: cscm.h:28
void join(bool verbose=false)
Joins the two SCM solutions.
Definition: cscm.h:361
CellTree(IDType cmid, const std::vector< IDType > &cells, const CellState &state, IDType imageCell)
Definition: cscm.h:22
IDType getImageCell() const
Definition: cscm.h:51
void setState(const CellState &state)
Definition: cscm.h:39
void setCells(const std::vector< IDType > &cells)
Definition: cscm.h:36
ClusteredSCM(SCM< CellType, IDType, StateVectorType > *scm1p, SCM< CellType, IDType, StateVectorType > *scm2p)
Definition: cscm.h:327
const SCMUniformCellStateSpace< CellType, IDType, StateVectorType > & getCss() const
Definition: scm.h:182
IDType getPeriodicGroups() const
Definition: scm.h:188
IDType getClusterID() const
Definition: cscm.h:42