ProcessModel& ProcessModel::operator=(const ProcessModel &other) { ListDigraph::NodeMap<ListDigraph::Node> noderef(other.graph); if (other.head == INVALID || other.tail == INVALID) { // The other is invalid => clear this one clear(); //Debugger::warn << "ProcessModel::operator= : The other PM is not valid!" << ENDL; return *this; } // Delete the saved stuff clearSaved(); // Delete the previous operations clearCurrent(); // Copy nodes and arc map of the process model digraphCopy(other.graph, this->graph).node(other.head, this->head).node(other.tail, this->tail).nodeRef(noderef).arcMap(other.p, this->p).arcMap(other.conjunctive, this->conjunctive).run(); // Create and copy the operations for (ListDigraph::NodeIt nit(other.graph); nit != INVALID; ++nit) { this->ops[noderef[nit]] = new Operation(*other.ops[nit]); } return *this; }
/* Clear hash part of table. */ static LJ_AINLINE void clearhpart(GCtab *t) { uint32_t i, hmask = t->hmask; Node *node = noderef(t->node); lua_assert(t->hmask != 0); for (i = 0; i <= hmask; i++) { Node *n = &node[i]; setmref(n->next, NULL); setnilV(&n->key); setnilV(&n->val); } }
void ProcessModel::restore() { if (!saved) { Debugger::err << "ProcessModel::restore : Trying to restore an empty PM!" << ENDL; return; } if (saved) { // clearCurrent(); // ####### TESTING // Remove all disjunctive arcs in the graph QList<ListDigraph::Arc> arcsToRem; for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { ListDigraph::Arc curArc = ait; if (!conjunctive[ait]) arcsToRem.append(curArc); } for (int i = 0; i < arcsToRem.size(); i++) { ListDigraph::Arc curArc = arcsToRem[i]; graph.erase(curArc); } // Restore the information about the operations for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { ListDigraph::Node curNode = nit; *(ops[curNode]) = savedOps[curNode]; } // Restore the DISJUNCTIVE arcs and the information about the arcs for (int i = 0; i < savedArcs.size(); i++) { if (!savedConjunctive[i]) { // This arc is disjunctive ListDigraph::Node curStartNode = savedArcs[i].first; ListDigraph::Node curEndNode = savedArcs[i].second; ListDigraph::Arc curArc = graph.addArc(curStartNode, curEndNode); p[curArc] = savedP[i]; conjunctive[curArc] = savedConjunctive[i]; } } // Restore the lengths of all arcs for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { ListDigraph::Node curNode = nit; double curP = ops[curNode]->p(); for (ListDigraph::OutArcIt oait(graph, curNode); oait != INVALID; ++oait) { ListDigraph::Arc curArc = oait; p[curArc] = -curP; } } // ################ return; // Copy the saved graph into the current one ListDigraph::NodeMap<ListDigraph::Node> noderef(savedGraph); digraphCopy(savedGraph, graph).node(savedHead, head).node(savedTail, tail).nodeRef(noderef).arcMap(savedp, p).arcMap(savedconjunctive, conjunctive).run(); // Create and copy the operations for (ListDigraph::NodeIt nit(savedGraph); nit != INVALID; ++nit) { this->ops[noderef[nit]] = new Operation(*savedops[nit]); } /* // Restore the operations for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { *ops[nit] = *savedOps[ops[nit]->ID]; } // Restore the arcs for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { arcsdel.append(ait); } for (int i = 0; i < arcsdel.size(); i++) { graph.erase(arcsdel[i]); } for (int i = 0; i < savedArcs.size(); i++) { arc = graph.addArc(savedArcs[i].first, savedArcs[i].second); p[arc] = savedP[i]; conjunctive[arc] = savedConjunctive[i]; } */ } //out1 << "Restored PM: " << *this << endl; }
void ProcessModel::save() { //out1 << "Saving PM ..." << endl; // Delete the previous operations clearSaved(); // Mark the PM to be saved saved = true; // ####### TESTING // Preserve the information about the operations savedOps.clear(); for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { ListDigraph::Node curNode = nit; Operation& curOp = (Operation&) * ops[curNode]; savedOps[curNode] = curOp; } // Preserve the information about the arcs savedArcs.clear(); savedP.clear(); savedConjunctive.clear(); for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { ListDigraph::Arc curArc = ait; ListDigraph::Node curStartNode = graph.source(curArc); ListDigraph::Node curEndNode = graph.target(curArc); savedArcs.append(QPair<ListDigraph::Node, ListDigraph::Node>(curStartNode, curEndNode)); savedP.append(p[curArc]); savedConjunctive.append(conjunctive[curArc]); } // ################ return; // Copy the current graph into the saved graph //out1 << "Copying the current graph..." << endl; ListDigraph::NodeMap<ListDigraph::Node> noderef(graph); digraphCopy(graph, this->savedGraph).node(head, this->savedHead).node(tail, savedTail).nodeRef(noderef).arcMap(p, savedp).arcMap(conjunctive, savedconjunctive).run(); //out1 << "Done copying the current graph." << endl; // Create and copy the operations //out1 << "Copying the current operations into the saved operations ..."<<endl; for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { this->savedops[noderef[nit]] = new Operation(*ops[nit]); } //out1 << "Done copying the current operations into the saved operations."<<endl; /* // Save the operations for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { savedOps[ops[nit]->ID] = new Operation(*ops[nit]); } // Save the arcs and the assigned data for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { savedArcs.append(QPair<ListDigraph::Node, ListDigraph::Node > (graph.source(ait), graph.target(ait))); savedP.append(p[ait]); savedConjunctive.append(conjunctive[ait]); } */ //out1 << "Saved PM: " << *this << endl; }
/* Hash values are masked with the table hash mask and used as an index. */ static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash) { Node *n = noderef(t->node); return &n[hash & t->hmask]; }