本文整理汇总了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);
//.........这里部分代码省略.........
示例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;
}