Partition ClusteringProjector::projectBackToFinest(const Partition& zetaCoarse,
		const std::vector<std::vector<node> >& maps, const Graph& Gfinest) {
	if (zetaCoarse.numberOfElements() == Gfinest.numberOfNodes()) {
		return zetaCoarse;
	}

	Partition zetaFine(Gfinest.upperNodeIdBound()); //Gfinest.numberOfNodes()
	zetaFine.setUpperBound(zetaCoarse.upperBound()); // upper bound for ids in zetaFine must be set to upper bound of zetaCoarse, or modularity assertions fail

	// store temporarily coarsest supernode here
	std::vector<node> tempMap(Gfinest.upperNodeIdBound()); //Gfinest.numberOfNodes()

	// initialize to identity
	Gfinest.parallelForNodes([&](node v){
		tempMap[v] = v;
	});

	// find coarsest supernode for each node
	for (auto iter = maps.begin(); iter != maps.end(); ++iter) {
		Gfinest.parallelForNodes([&](node v){
			tempMap[v] = (* iter)[tempMap[v]];
		});
	}


	// set clusters for fine nodes
	Gfinest.parallelForNodes([&](node v) {
		index sc = zetaCoarse[tempMap[v]];
		zetaFine.addToSubset(sc,v);//zetaFine[v] = sc;
	});

	return zetaFine;
}
void Rubik::rotateCubeU() {
	U(false);
	Di(false);
	this->shift(this->middle, 4, 5, 3, 0);
	this->shift(this->edges, 1, 10, 11, 15);
	this->shift(this->edges, 23, 3, 13, 22);

	std::map<std::string, std::string> tempMap(movesDictionary);
	//Dictionary

	movesDictionary[_R] = tempMap[_B];
	movesDictionary[_Ri] = tempMap[_Bi];
	movesDictionary[_R2] = tempMap[_B2];
	movesDictionary[_L] = tempMap[_F];
	movesDictionary[_Li] = tempMap[_Fi];
	movesDictionary[_L2] = tempMap[_F2];
	/*movesDictionary[_U] = tempMap[_U];
	movesDictionary[_Ui] = tempMap[_Ui];
	movesDictionary[_U2] = tempMap[_U2];
	movesDictionary[_D] = tempMap[_D];
	movesDictionary[_Di] = tempMap[_Di];
	movesDictionary[_D2] = tempMap[_D2];*/
	movesDictionary[_B] = tempMap[_L];
	movesDictionary[_Bi] = tempMap[_Li];
	movesDictionary[_B2] = tempMap[_L2];
	movesDictionary[_F] = tempMap[_R];
	movesDictionary[_Fi] = tempMap[_Ri];
	movesDictionary[_F2] = tempMap[_R2];

}
void Rubik::turnCubeLeft() { //White to green
	F(false);
	Bi(false);
	this->shift(this->middle, 3, 2, 4, 1);
	this->shift(this->edges, 6, 20, 9, 19);
	this->shift(this->edges, 7, 18, 8, 21);

	std::map<std::string, std::string> tempMap(movesDictionary);
	//Dictionary

	movesDictionary[_R] = tempMap[_U];
	movesDictionary[_Ri] = tempMap[_Ui];
	movesDictionary[_R2] = tempMap[_U2];
	movesDictionary[_L] = tempMap[_D];
	movesDictionary[_Li] = tempMap[_Di];
	movesDictionary[_L2] = tempMap[_D2];
	movesDictionary[_U] = tempMap[_L];
	movesDictionary[_Ui] = tempMap[_Li];
	movesDictionary[_U2] = tempMap[_L2];
	/*movesDictionary[_B] = movesDictionary[_B];
	movesDictionary[_Bi] = movesDictionary[_Bi];
	movesDictionary[_B2] = movesDictionary[_B2];
	movesDictionary[_F] = movesDictionary[_F];
	movesDictionary[_Fi] = movesDictionary[_Fi];
	movesDictionary[_F2] = movesDictionary[_F2];*/
	movesDictionary[_D] = tempMap[_R];
	movesDictionary[_Di] = tempMap[_Ri];
	movesDictionary[_D2] = tempMap[_R2];

}
void Rubik::turnCubeDown() { //White to red
	R(false);
	Li(false);
	this->shift(this->middle, 0, 2, 5, 1);
	this->shift(this->edges, 4, 0, 14, 17);
	this->shift(this->edges, 12, 2, 5, 16);

	std::map<std::string, std::string> tempMap(movesDictionary);

	//Dictionary
	/*movesDictionary[movesDictionary[_R]] = movesDictionary[_R];
	movesDictionary[movesDictionary[_Ri]] = movesDictionary[_Ri];
	movesDictionary[movesDictionary[_R2]] = movesDictionary[_R2];
	movesDictionary[movesDictionary[_L]] = movesDictionary[_L];
	movesDictionary[movesDictionary[_Li]] = movesDictionary[_Li];
	movesDictionary[movesDictionary[_L2]] = movesDictionary[_L2];*/
	movesDictionary[_U] = tempMap[_F];
	movesDictionary[_Ui] = tempMap[_Fi];
	movesDictionary[_U2] = tempMap[_F2];
	movesDictionary[_B] = tempMap[_U];
	movesDictionary[_Bi] = tempMap[_Ui];
	movesDictionary[_B2] = tempMap[_U2];
	movesDictionary[_F] = tempMap[_D];
	movesDictionary[_Fi] = tempMap[_Di];
	movesDictionary[_F2] = tempMap[_D2];
	movesDictionary[_D] = tempMap[_B];
	movesDictionary[_Di] = tempMap[_Bi];
	movesDictionary[_D2] = tempMap[_B2];

}
void Rubik::turnCubeUp() { //White to orange
	Ri(false);
	L(false);
	this->shift(this->middle, 0, 1, 5, 2);
	this->shift(this->edges, 4, 17, 14, 0);
	this->shift(this->edges, 12, 16, 5, 2);

	std::map<std::string, std::string> tempMap(movesDictionary);
	//Dictionary
	/*movesDictionary[movesDictionary[_R]] = movesDictionary[_R];
	movesDictionary[movesDictionary[_Ri]] = movesDictionary[_Ri];
	movesDictionary[movesDictionary[_R2]] = movesDictionary[_R2];
	movesDictionary[movesDictionary[_L]] = movesDictionary[_L];
	movesDictionary[movesDictionary[_Li]] = movesDictionary[_Li];
	movesDictionary[movesDictionary[_L2]] = movesDictionary[_L2];*/
	movesDictionary[_U] = tempMap[_B];
	movesDictionary[_Ui] = tempMap[_Bi];
	movesDictionary[_U2] = tempMap[_B2];
	movesDictionary[_B] = tempMap[_D];
	movesDictionary[_Bi] = tempMap[_Di];
	movesDictionary[_B2] = tempMap[_D2];
	movesDictionary[_F] = tempMap[_U];
	movesDictionary[_Fi] = tempMap[_Ui];
	movesDictionary[_F2] = tempMap[_U2];
	movesDictionary[_D] = tempMap[_F];
	movesDictionary[_Di] = tempMap[_Fi];
	movesDictionary[_D2] = tempMap[_F2];
}
void Rubik::turnCubeRight() { //White to blue
	Fi(false);
	B(false);
	this->shift(this->middle, 3, 1, 4, 2);
	this->shift(this->edges, 6, 19, 9, 20);
	this->shift(this->edges, 7, 21, 8, 18);

	std::map<std::string, std::string> tempMap(movesDictionary);
	//Dictionary
	movesDictionary[_R] = tempMap[_D];
	movesDictionary[_Ri] = tempMap[_Di];
	movesDictionary[_R2] = tempMap[_D2];
	movesDictionary[_L] = tempMap[_U];
	movesDictionary[_Li] = tempMap[_Ui];
	movesDictionary[_L2] = tempMap[_U2];
	movesDictionary[_U] = tempMap[_R];
	movesDictionary[_Ui] = tempMap[_Ri];
	movesDictionary[_U2] = tempMap[_R2];
	/*movesDictionary[_B] = movesDictionary[_B];
	movesDictionary[_Bi] = movesDictionary[_Bi];
	movesDictionary[_B2] = movesDictionary[_B2];
	movesDictionary[_F] = movesDictionary[_F];
	movesDictionary[_Fi] = movesDictionary[_Fi];
	movesDictionary[_F2] = movesDictionary[_F2];*/
	movesDictionary[_D] = tempMap[_L];
	movesDictionary[_Di] = tempMap[_Li];
	movesDictionary[_D2] = tempMap[_L2];

}
Example #7
0
void util::ThreadedParser::run(){
    srtl_driver* driver = util::getDriver(m_argc, m_args);
    std::map<std::string, Pattern*> tab = driver->getSymTab();
    for(std::map<std::string, Pattern*>::iterator iter = tab.begin(); iter != tab.end(); iter++){
        ConcretePattern* p = dynamic_cast<ConcretePattern*>(tab[iter->first]);
        AbstPattern* ap = dynamic_cast<AbstPattern*>(tab[iter->first]);
        if(p != NULL){
            Node* tree = p->getTree();
            p->trav(tree);
            cerr << p->getName() << " " << p->getLineStart() << " " << endl;//p->getLineEnd() << endl;
            util::NodeMap::display(tree);

            std::vector<Operand> opVec = p->getOperands();
            std::deque<Operand> deck(opVec.begin(), opVec.end());
            util::NodeMap::setOpDeque(deck);
            util::NodeMap::createNodeMap(tree);
            std::map<int, std::vector<BNode*> > nodeMap = util::NodeMap::getNodeMap();
            std::map<int, std::vector<BNode*> > tempMap(nodeMap.begin(), nodeMap.end());    //copy the map

            PatternDTO* dto = new PatternDTO();
            dto->setMap(tempMap);
            dto->setName(p->getName());
            dto->setLineStart(p->getLineStart());
            util::NodeMap::m_mapVec.push_back(dto);
            dfsFlag = 0;
            util::NodeMap::doDepthFirstSearch(tree);
        }
        if(ap!=NULL && ap->resolved){
            Node* tree = ap->getTree();
            //cerr << "++++++"<<ap->getPatName() << " " << ap->getLineStart() << " " << endl;//p->getLineEnd() << endl;
            util::NodeMap::display(tree);
            util::NodeMap::createNodeMap(tree);
            std::map<int, std::vector<BNode*> > nodeMap = util::NodeMap::getNodeMap();
            std::map<int, std::vector<BNode*> > tempMap(nodeMap.begin(), nodeMap.end());    //copy the map

            PatternDTO* dto = new PatternDTO();
            dto->setMap(tempMap);
            dto->setName(ap->getPatName());
            dto->setLineStart(ap->getLineStart());
            util::NodeMap::m_mapVec.push_back(dto);
        }
    }
}
Example #8
0
//=============================================================================
bool CArea::OnLoad(char* File) {
    OnCleanup();

	FILE* FileHandle;
	errno_t err = fopen_s(&FileHandle, File, "r");

    if(FileHandle == NULL || err != 0) {
		debug("Error: Couldn't open area file.");
        return false;
    }
    char TilesetFile[255];

	// Load tileset picture to a surface
    fscanf_s(FileHandle, "%s\n", TilesetFile);
    if((Surf_Tileset = CSurface::OnLoad(TilesetFile)) == false) {
        fclose(FileHandle);
		debug("Error: Couldn't load tileset for area.");
        return false;
    }

	// Load maps to CAreas MapList
	int numberOfMaps;
	fscanf_s(FileHandle, "%d\n", &numberOfMaps);

	for(int X = 0;X < numberOfMaps;X++) {
		char MapFile[255];

		fscanf_s(FileHandle, "%s ", MapFile);

		// Load map's tileset into map's Tilelist
		CMap tempMap(X);
		if(tempMap.OnLoad(MapFile) == false) {
			fclose(FileHandle);
			debug("Error: Couldn't load tilset for map.");
			return false;
		}

		tempMap.Surf_Tileset = Surf_Tileset;
		MapList.push_back(tempMap);
		fscanf_s(FileHandle, "\n");
	}

    fclose(FileHandle);

	std::string filename = File;
	debug("Loaded area " + filename, 2);
    return true;
}