当前位置: 首页>>代码示例>>C++>>正文


C++ Automaton::getTypeId方法代码示例

本文整理汇总了C++中Automaton::getTypeId方法的典型用法代码示例。如果您正苦于以下问题:C++ Automaton::getTypeId方法的具体用法?C++ Automaton::getTypeId怎么用?C++ Automaton::getTypeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Automaton的用法示例。


在下文中一共展示了Automaton::getTypeId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

void ConnectivityGlobalPlugin::update(CC3DXMLElement *_xmlData, bool _fullInitFlag) {

	if (potts->getDisplayUnitsFlag()) {
		Unit energyUnit = potts->getEnergyUnit();




		CC3DXMLElement * unitsElem = _xmlData->getFirstElement("Units");
		if (!unitsElem) { //add Units element
			unitsElem = _xmlData->attachElement("Units");
		}

		if (unitsElem->getFirstElement("PenaltyUnit")) {
			unitsElem->getFirstElement("PenaltyUnit")->updateElementValue(energyUnit.toString());
		}
		else {
			CC3DXMLElement * energyElem = unitsElem->attachElement("PenaltyUnit", energyUnit.toString());
		}
	}

	penaltyVec.clear();

	Automaton *automaton = potts->getAutomaton();
	ASSERT_OR_THROW("CELL TYPE PLUGIN WAS NOT PROPERLY INITIALIZED YET. MAKE SURE THIS IS THE FIRST PLUGIN THAT YOU SET", automaton)
		set<unsigned char> cellTypesSet;


	map<unsigned char, double> typeIdConnectivityPenaltyMap;

	if (_xmlData->getFirstElement("DoNotPrecheckConnectivity")) {
		doNotPrecheckConnectivity = true;
	}

	if (_xmlData->getFirstElement("FastAlgorithm")) {
		fast_algorithm = true;
		changeEnergyFcnPtr = &ConnectivityGlobalPlugin::changeEnergyFast;
	}


	CC3DXMLElementList penaltyVecXML = _xmlData->getElements("Penalty");

	CC3DXMLElementList connectivityOnVecXML = _xmlData->getElements("ConnectivityOn");

	ASSERT_OR_THROW("You cannot use Penalty and ConnectivityOn tags together. Stick to one convention", !(connectivityOnVecXML.size() && penaltyVecXML.size()));

	// previous ASSERT_OR_THROW will encure that only one of the subsequent for loops be executed 

	for (int i = 0; i < penaltyVecXML.size(); ++i) {
		typeIdConnectivityPenaltyMap.insert(make_pair(automaton->getTypeId(penaltyVecXML[i]->getAttribute("Type")), penaltyVecXML[i]->getDouble()));


		//inserting all the types to the set (duplicate are automatically eleminated) to figure out max value of type Id
		cellTypesSet.insert(automaton->getTypeId(penaltyVecXML[i]->getAttribute("Type")));

	}



	for (int i = 0; i < connectivityOnVecXML.size(); ++i) {
		typeIdConnectivityPenaltyMap.insert(make_pair(automaton->getTypeId(connectivityOnVecXML[i]->getAttribute("Type")), 1.0));
		//inserting all the types to the set (duplicate are automatically eleminated) to figure out max value of type Id
		cellTypesSet.insert(automaton->getTypeId(connectivityOnVecXML[i]->getAttribute("Type")));

	}


	//Now that we know all the types used in the simulation we will find size of the penaltyVec
	vector<unsigned char> cellTypesVector(cellTypesSet.begin(), cellTypesSet.end());//coping set to the vector

	int size = 0;
	if (cellTypesVector.size()) {
		size = *max_element(cellTypesVector.begin(), cellTypesVector.end());
	}

	maxTypeId = size;

	size += 1;//if max element is e.g. 5 then size has to be 6 for an array to be properly allocated



	int index;
	penaltyVec.assign(size, 0.0);
	//inserting connectivity penalty values to penaltyVec;
	for (map<unsigned char, double>::iterator mitr = typeIdConnectivityPenaltyMap.begin(); mitr != typeIdConnectivityPenaltyMap.end(); ++mitr) {
		penaltyVec[mitr->first] = fabs(mitr->second);
	}

	cerr << "size=" << size << endl;
	for (int i = 0; i < size; ++i) {
		cerr << "penaltyVec[" << i << "]=" << penaltyVec[i] << endl;
	}

	//Here I initialize max neighbor index for direct acces to the list of neighbors 
	boundaryStrategy = BoundaryStrategy::getInstance();
	maxNeighborIndex = 0;


	maxNeighborIndex = boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(1);

//.........这里部分代码省略.........
开发者ID:CompuCell3D,项目名称:CompuCell3D,代码行数:101,代码来源:ConnectivityGlobalPlugin.cpp

示例2: update

void ConnectivityGlobalPlugin::update(CC3DXMLElement *_xmlData, bool _fullInitFlag){

	if(potts->getDisplayUnitsFlag()){
		Unit energyUnit=potts->getEnergyUnit();




		CC3DXMLElement * unitsElem=_xmlData->getFirstElement("Units"); 
		if (!unitsElem){ //add Units element
			unitsElem=_xmlData->attachElement("Units");
		}

		if(unitsElem->getFirstElement("PenaltyUnit")){
			unitsElem->getFirstElement("PenaltyUnit")->updateElementValue(energyUnit.toString());
		}else{
			CC3DXMLElement * energyElem = unitsElem->attachElement("PenaltyUnit",energyUnit.toString());
		}
	}

	penaltyVec.clear();

	Automaton *automaton = potts->getAutomaton();
	ASSERT_OR_THROW("CELL TYPE PLUGIN WAS NOT PROPERLY INITIALIZED YET. MAKE SURE THIS IS THE FIRST PLUGIN THAT YOU SET", automaton)
		set<unsigned char> cellTypesSet;

	
	map<unsigned char,double> typeIdConnectivityPenaltyMap;

	if(_xmlData->getFirstElement("DoNotPrecheckConnectivity")){
		doNotPrecheckConnectivity=true;
	}

	CC3DXMLElementList penaltyVecXML=_xmlData->getElements("Penalty");

	

	for (int i = 0 ; i<penaltyVecXML.size(); ++i){
		typeIdConnectivityPenaltyMap.insert(make_pair(automaton->getTypeId(penaltyVecXML[i]->getAttribute("Type")),penaltyVecXML[i]->getDouble()));


		//inserting all the types to the set (duplicate are automatically eleminated) to figure out max value of type Id
		cellTypesSet.insert(automaton->getTypeId(penaltyVecXML[i]->getAttribute("Type")));


	}

	
	//Now that we know all the types used in the simulation we will find size of the penaltyVec
	vector<unsigned char> cellTypesVector(cellTypesSet.begin(),cellTypesSet.end());//coping set to the vector

	int size=0;
	if (cellTypesVector.size()){
		size= * max_element(cellTypesVector.begin(),cellTypesVector.end());
	}

	maxTypeId=size;

	size+=1;//if max element is e.g. 5 then size has to be 6 for an array to be properly allocated

	

	int index ;
	penaltyVec.assign(size,0.0);
	//inserting connectivity penalty values to penaltyVec;
	for(map<unsigned char , double>::iterator mitr=typeIdConnectivityPenaltyMap.begin() ; mitr!=typeIdConnectivityPenaltyMap.end(); ++mitr){
		penaltyVec[mitr->first]=fabs(mitr->second);
	}

	cerr<<"size="<<size<<endl;
	for(int i = 0 ; i < size ; ++i){
		cerr<<"penaltyVec["<<i<<"]="<<penaltyVec[i]<<endl;
	}

	//Here I initialize max neighbor index for direct acces to the list of neighbors 
	boundaryStrategy=BoundaryStrategy::getInstance();
	maxNeighborIndex=0;


	maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(1);


	cerr<<"ConnectivityGlobal maxNeighborIndex="<<maxNeighborIndex<<endl;   

}
开发者ID:AngeloTorelli,项目名称:CompuCell3D,代码行数:85,代码来源:ConnectivityGlobalPlugin.cpp


注:本文中的Automaton::getTypeId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。