Node Dlite::GetMinPredecessor(Node* current, LocalMap &map) { Node* min; std::vector<Node *> all_neighbors; for(auto elem : FindNeighbors(current, map)) { if(!NODES.count(vertex(elem.point, map.height))) { //if vertex wasn't previously examined elem.g = std::numeric_limits<double>::infinity(); elem.rhs = std::numeric_limits<double>::infinity(); NODES[vertex(elem.point, map.height)] = elem; all_neighbors.push_back(&(NODES.find(vertex(elem.point, map.height))->second)); } else { all_neighbors.push_back(&(NODES.find(vertex(elem.point, map.height))->second)); } } Node min_node; if (!all_neighbors.empty()) { min = (all_neighbors.front()); min_node = *min; min_node.rhs = std::numeric_limits<double>::infinity(); min_node.parent = min; for (auto n: all_neighbors) { if (min_node.rhs > n->g + GetCost(n->point, current->point, map)) { min_node.rhs = n->g + GetCost(n->point, current->point, map); min_node.parent = n; } } } else { min_node.parent = nullptr; } return min_node; }
bool Dlite::ComputeShortestPath(LocalMap &map) { while (OPEN.top_key_less_than(CalculateKey(*start)) || start->rhs != start->g) { ++number_of_steps; Node* current = OPEN.get();\ Key old_key = current->key; Key new_key = CalculateKey(*current); if (old_key < new_key) { current->key = new_key; OPEN.put(current); } else if (current->g > current->rhs) { current->g = current->rhs; OPEN.pop(); for (auto elem : GetSuccessors(current, map)) { if (elem->point != map.goal && elem->rhs > current->g + GetCost(elem->point, current->point, map)) { elem->parent = current; elem->rhs = current->g + GetCost(elem->point, current->point, map); } UpdateVertex(elem); // !!!<-apparently OK } } else { //double old_g = current->g; current->g = std::numeric_limits<double>::infinity(); std::vector<Node* > succ = GetSuccessors(current, map); succ.push_back(current); for (auto elem : succ) { if (elem->point != map.goal && elem->parent->point == current->point) { Node min_val = GetMinPredecessor(elem, map); elem->rhs = min_val.rhs; if(min_val.parent) elem->parent = min_val.parent; } UpdateVertex(elem); } } /*if(current->parent) { std::cout << current->point << "g " << current->g << " rhs" << current->rhs << current->parent->point << std::endl; } */ //std::cout << OPEN.top_key().k1 << std::endl; //OPEN.print_elements(); } if (start->rhs != std::numeric_limits<double>::infinity()) { current_result.pathfound = true; current_result.numberofsteps = number_of_steps; current_result.nodescreated = NODES.size(); //std::cout << start->rhs << std::endl; //MakePrimaryPath(start); //current_result.lppath = &path; //map.PrintPath(curpath); //for (auto elem : curpath) path.push_back(elem); return true; } else { current_result.pathfound = false; current_result.pathlength = 0; return false; } return false; }
void BUILDING::TrainUnit(int unit) { if(m_pPlayer->money < GetCost(unit, false))return; m_training = true; m_trainingUnit = unit; m_trainingTime = 0.0f; m_pPlayer->money -= GetCost(unit, false); if(unit == WORKER)m_maxTrainingTime = 15.0f; if(unit == SOLDIER)m_maxTrainingTime = 20.0f; if(unit == MAGICIAN)m_maxTrainingTime = 30.0f; }
Model* CreateModel(const Schema& schema, const std::vector<size_t>& pred, size_t index, double err) { int cost = GetCost(pred, index); if (cost == 1000000) return NULL; return new MockModel(pred, index); }
float IBAction::GetTotalCost() const { float fTotal = GetCost(); if (m_pPostWorldChange != nullptr && m_pPostWorldChange->GetAction() != nullptr) fTotal += m_pPostWorldChange->GetAction()->GetTotalCost(); return fTotal; }
void psCreationManager::AddChoice( int choice, int modifier ) { if(!GetChoice(choice)) { Error2("Invalid creation choice: %i", choice); return; } choicesMade.Push( choice ); currentCP-=GetCost( choice )*modifier; }
QGraphicsSimpleTextItem* MapDesignerConnection::GetCostTextItem(QFont font) const { auto costString = std::to_string(GetCost()); auto costLocation = GetCostLocation(font); auto costTextItem = new QGraphicsSimpleTextItem(QString::fromStdString(costString)); costTextItem->setPos(costLocation); costTextItem->setFont(font); return costTextItem; }
void psCreationManager::RemoveChoice( uint32_t choice, int modifier ) { for ( size_t x = 0; x < choicesMade.GetSize(); x++ ) { if ( choicesMade[x] == choice ) { currentCP += GetCost( choicesMade[x] )*modifier; choicesMade.DeleteIndex(x); return; } } }
//============================================================================ // NCache::NeedsPurge : Does the cache need to purge? //---------------------------------------------------------------------------- bool NCache::NeedsPurge(void) { bool needsPurge; // Check our state needsPurge = false; if (mMaxSize != 0 && GetSize() > mMaxSize) needsPurge = true; if (mMaxCost != 0 && GetCost() > mMaxCost) needsPurge = true; return(needsPurge); }
// Reference code (it's in document) void AStar::FindPath(Node *start, Node *end) { start->SetF(0); start->SetG(0); start->SetH(0); this->PushNode(start); while (open.count() > 0) { // Find node by lowest F value Node *node = this->PopNode(); this->IncreaseNodeCount(); if (node == end) { this->ReconstructPath(end); return; } closed.append(node); for (int i = 0; i < node->GetConnectors().count(); i++) { Connector *connector = node->GetConnectors().at(i); Node *neighbour = connector->GetChild(); if (this->closed.contains(neighbour)) continue; double g = node->GetG() + GetCost(node,connector); if (!open.contains(neighbour) || g < neighbour->GetG()) { neighbour->SetParent(node); neighbour->SetG(g); neighbour->SetH(GetHeuristic(neighbour,end)); neighbour->SetF(neighbour->GetG() + neighbour->GetH()); //this->IncreaseNodeCount(); if (!this->open.contains(neighbour)) this->PushNode(neighbour); } } } this->ReconstructPath(end); }
void YARPViterbi::ShowPath() { CalculatePath(); for (int i=0; i<index; i++) { if (path(0,i)==-1) { printf("*"); } else { printf("%d",path(0,i)); } if (K>=10) { printf(" "); } } printf(" costs %g\n", GetCost()); }
//Function used to calculate the path from start to finish. void CalculatePath(SCoords* currentNode, int mapArray[10][10], int newCost, int existingCost, SCoords &node, SCoords mapEnd, deque <unique_ptr < SCoords > > &openList, deque <unique_ptr < SCoords > > &closedList, bool &validNode) { int wallCost = 0; int arrayOffset = 9;//An offset is needed for the array because a 2 dimensional array starts from the top left but the map coordinate system starts in the bottom right. existingCost = GetCost(openList, closedList, node);//This is used to store the existing cost of the newly generated node if it is already on open or closed list. newCost = currentNode->cost + mapArray[arrayOffset - node.y][node.x];//newCost is the cost of the new node generated by adding the terrain cost of the new node to the cost of its parent, //in this case the current node. if (mapArray[arrayOffset - node.y][node.x] != wallCost)//This check is used to ensure that any nodes that happen to be walls are not added to the lists because we cannot move through walls. { //We then check to see if the newly generated node is already on the open or closed lists //and if its new cost is greater than the cost of the node on the list then the new node is discarded. if ((FindValue(openList, node) || FindValue(closedList, node)) && newCost >= existingCost) { return; } else { validNode = true; node.pParent = currentNode;//We set the parent of the new node to the current node to allow us to create a route by following the parent chain. node.score = newCost + HeuristicCalc(mapEnd, node); node.cost = newCost; //We then check to see if the new node is on open or closed list. if (FindValue(openList, node) || FindValue(closedList, node)) { //If the value is on the closed list then we need to remove it from the closed list and add the new value to open list. if (FindValue(closedList, node)) { FindValueRemove(closedList, node, openList); } } //We then check if the value isnt on either list. If it isn't then we add it to open list as it is a node that hasn't previously been generated. if (!FindValue(openList, node) || !FindValue(closedList, node)) { InsertNode(openList, node); } } } }
void CRUTask::ComputeGain() { TInt32 gain=0, maxGain=0; // First, update the (local) cost estimate ComputeCost(); // Next, update the (global) gain estimate DSListPosition pos = pSuccList_->GetHeadPosition(); // Compute the maximum gain between successor tasks while (NULL != pos) { CRUTask *pSuccTask = pSuccList_->GetNext(pos); gain = pSuccTask->GetGain(); maxGain = (gain > maxGain) ? gain : maxGain; } // Update the gain gain_ = GetCost() + maxGain; }
void AMod::CharacterPurchasedMod(APlayerCharacter* buyer) { if (!IsValid(buyer)) return; buyer->ChangeCredits(-1 * GetCost(true, buyer)); TArray<TSubclassOf<AMod> > classList; GetRecipe(classList); TArray<AMod*> mods = buyer->GetMods(); for (int32 i = 0; i < classList.Num(); i++) { for (int32 j = 0; j < mods.Num(); j++) { if (mods[j]->GetClass() == classList[i]) { buyer->RemoveMod(j); mods.RemoveAt(j); classList.RemoveAt(i); } } } }
bool Abil_bloodreload::ActivePlayer(Player* player_) { player_->SetBloodReload(GetCost()); return true; }
cNewO_CombineCple::cNewO_CombineCple(const cStructMergeTieP< cFixedSizeMergeTieP<2,Pt2dr> > & aMap,ElRotation3D * aTestSol) : mCurStep (1<<NbPow2), mNbStepTeta (4 * NbDecoup0PIS2 * mCurStep), mCurRot (3,3), mW (0) { // REDONDANT AVEC FONCTION GLOBALES FAITE APRES .... PackReduit /******************************************************/ /* */ /* A- Selection des sommets */ /* */ /******************************************************/ //------------------------------------------------------------------------ // A- 1- Preselrection purement aleatoire d'un nombre raisonnable depoints //------------------------------------------------------------------------ const std::list<tMerge *> & aLM = aMap.ListMerged(); RMat_Inertie aMat; { cRandNParmiQ aSelec(NbMaxInit, (int)aLM.size()); for (std::list<tMerge *>::const_iterator itM=aLM.begin() ; itM!=aLM.end() ; itM++) { if (aSelec.GetNext()) { mVAllCdt.push_back(cCdtCombTiep(*itM)); Pt2dr aP1 = (*itM)->GetVal(0); aMat.add_pt_en_place(aP1.x,aP1.y); } } } aMat = aMat.normalize(); int aNbSomTot = int(mVAllCdt.size()); double aSurfType = sqrt (aMat.s11()* aMat.s22() - ElSquare(aMat.s12())); double aDistType = sqrt(aSurfType/aNbSomTot); double aSzW = 800; if (1) { mP0W = aMap.ValInf(0); Pt2dr aP1 = aMap.ValSup(0); Pt2dr aSz = aP1-mP0W; mP0W = mP0W - aSz * 0.1; aP1 = aP1 + aSz * 0.1; aSz = aP1-mP0W; mScaleW = aSzW /ElMax(aSz.x,aSz.y) ; mW = Video_Win::PtrWStd(round_ni(aSz*mScaleW)); } //------------------------------------------------------------------------ // A-2 Calcul d'une fonction de deponderation //------------------------------------------------------------------------ for (int aKS1 = 0 ; aKS1 <aNbSomTot ; aKS1++) { for (int aKS2 = aKS1 ; aKS2 <aNbSomTot ; aKS2++) { // sqrt pour attenuer la ponderation double aDist = sqrt(dist48( mVAllCdt[aKS1].mP1-mVAllCdt[aKS2].mP1) / 2.0); // aDist=1; // double aDist = (dist48( mVAllCdt[aKS1].mP1-mVAllCdt[aKS2].mP1) / 2.0); double aPds = 1 / (aDistType+aDist); mVAllCdt[aKS1].mPdsOccup += aPds; mVAllCdt[aKS2].mPdsOccup += aPds; } if (mW) mW->draw_circle_abs(ToW( mVAllCdt[aKS1].mP1),2.0,mW->pdisc()(P8COL::blue)); } for (int aKSom = 0 ; aKSom <aNbSomTot ; aKSom++) { cCdtCombTiep & aCdt = mVAllCdt[aKSom]; aCdt.mPdsOccup *= ElSquare(aCdt.mMerge->NbArc()); } int aNbSomSel = ElMin(aNbSomTot,NbTieP); //------------------------------------------------------------------------ // A-3 Calcul de aNbSomSel points biens repartis //------------------------------------------------------------------------ ElTimer aChrono; for (int aKSel=0 ; aKSel<aNbSomSel ; aKSel++) { // Recherche du cdt le plus loin double aMaxDMin = 0; cCdtCombTiep * aBest = 0; for (int aKSom = 0 ; aKSom <aNbSomTot ; aKSom++) { cCdtCombTiep & aCdt = mVAllCdt[aKSom]; double aDist = aCdt.mDMin * aCdt.mPdsOccup; if ((!aCdt.mTaken) && (aDist > aMaxDMin)) { aMaxDMin = aDist; aBest = & aCdt; } } ELISE_ASSERT(aBest!=0,"cNewO_CombineCple"); for (int aKSom = 0 ; aKSom <aNbSomTot ; aKSom++) { cCdtCombTiep & aCdt = mVAllCdt[aKSom]; aCdt.mDMin = ElMin(aCdt.mDMin,dist48(aCdt.mP1-aBest->mP1)); } aBest->mQ1 = vunit(Pt3dr(aBest->mP1.x,aBest->mP1.y,1.0)); Pt2dr aP2 = aBest->mMerge->GetVal(1); aBest->mQ2Init = vunit(Pt3dr(aP2.x,aP2.y,1.0)); mVCdtSel.push_back(aBest); if (mW) mW->draw_circle_abs(ToW( aBest->mP1),3.0,mW->pdisc()(P8COL::red)); } /******************************************************/ /* */ /* B- Calcul des arcs */ /* */ /******************************************************/ // B-1 Au max le nombre d'arc possible int aNbA = NbCple; while (aNbA > ((aNbSomSel * (aNbSomSel-1)) /2)) aNbA--; int aNbIter = (aNbA-1) / aNbSomSel + 1; cRandNParmiQ aSelec(aNbA- (aNbIter-1) * aNbSomSel,aNbSomSel); int aNbAMaj = aNbIter * aNbSomSel; std::vector<int> aPermut = RandPermut(aNbA); // B-2 Recherche des arsc int aKA=0; for (int aCptAMaj = 0 ; aCptAMaj < aNbAMaj ; aCptAMaj++) { // Tous les sommets sont equi repartis, sauf a la fin on choisit a hasard bool aSelK = true; if ( (aCptAMaj/aNbSomSel)== (aNbIter-1)) // Si derniere iter, test special { aSelK = aSelec.GetNext(); } if (aSelK) { int aKP1 = (aCptAMaj%aNbSomSel); double aTeta = (aPermut[aKA] * 2 * PI) / aNbA; Pt2dr aDir = Pt2dr::FromPolar(1.0,aTeta); // std::cout << "teta " << aTeta << "\n"; double aBestSc=-1.0; int aBestK=-1; for (int aKP2 = 0 ; aKP2 < aNbSomSel ; aKP2++) { if (aKP2!=aKP1) { Pt2dr aV = (mVCdtSel[aKP2]->mP1- mVCdtSel[aKP1]->mP1) / aDir; Pt2dr aU = vunit(aV); // Favorise les llongs arc et homogeneise les directions double aSc = NRrandom3() * euclid(aV) * (1/(1+ElSquare(5.0*aU.y))); if ((aSc>aBestSc) && (aKP2!=aKP1)) { aBestSc= aSc; aBestK = aKP2; } } } ELISE_ASSERT((aBestK>=0),"No Best Arc"); mLArcs.push_back(Pt2di(aKP1,aBestK)); if (mW) { mW->draw_seg(ToW( mVCdtSel[aKP1]->mP1),ToW( mVCdtSel[aBestK]->mP1),mW->pdisc()(P8COL::green)); } aKA++; } } /******************************************************/ /* */ /* */ /* */ /******************************************************/ if (mW) mW->clik_in(); if (aTestSol) { ElRotation3D aR = * aTestSol; // Le sens corret a ete retabli (j'espere !!) // SetCurRot(aR.Mat()); // std::cout << "Test Externe : " << CalculCostCur() <<"\n"; // aR = aR.inv(); SetCurRot(aR.Mat()); std::cout << "Test Externe I : " << CalculCostCur() <<"\n"; std::cout << "CostBase " << CostOneBase(aR.tr()) << "\n"; // ElRotation3D * } std::cout << "cNewO_CombineCple::cNewO_CombineCple " << aNbSomTot << "\n"; Pt3di aP; std::list<Pt3di> aLPMin; double aCostMin = 1e10; Pt3di aPMin(1000,1000,1000); for (aP.x = -NbDecoup0PIS2 ; aP.x <= NbDecoup0PIS2 ; aP.x ++) { std::cout << "DECx " << aP.x << "\n"; for (aP.y = -NbDecoup0PIS2 ; aP.y <= NbDecoup0PIS2 ; aP.y ++) { for (aP.z = - (2*NbDecoup0PIS2) ; aP.z < (2*NbDecoup0PIS2) ; aP.z ++) { double aVC = GetCost(aP*mCurStep); bool IsMinLoc = (aVC < GetCost((aP+Pt3di( 1,0,0)) * mCurStep)) && (aVC < GetCost((aP+Pt3di(-1,0,0)) * mCurStep)) && (aVC < GetCost((aP+Pt3di(0, 1,0)) * mCurStep)) && (aVC < GetCost((aP+Pt3di(0,-1,0)) * mCurStep)) && (aVC < GetCost((aP+Pt3di(0,0, 1)) * mCurStep)) && (aVC < GetCost((aP+Pt3di(0,0,-1)) * mCurStep)); int aDelta = 2; for (int aDx=-aDelta ; (aDx<=aDelta) && IsMinLoc ; aDx++) { for (int aDy=-aDelta ; (aDy<=aDelta) && IsMinLoc ; aDy++) { for (int aDz=-aDelta ; (aDz<=aDelta) && IsMinLoc ; aDz++) { if ((aDx!=0) || (aDy!=0) || (aDz!=0)) { IsMinLoc = IsMinLoc && (aVC<GetCost( (aP+Pt3di(aDx,aDy,aDz))*mCurStep)); } } } } if (IsMinLoc) { std::cout << " IisssMinn " << aP << " " << aVC << "\n"; aLPMin.push_back(aP*mCurStep); } if (aVC<aCostMin) { aPMin = aP*mCurStep; aCostMin = aVC; } } } } std::cout << "COST " << aCostMin << " PMIN " << PInt2Tetas(aPMin ) << " NbMinLoc " << aLPMin.size() << "\n"; Pt3dr aTeta = PInt2Tetas(aPMin); ElMatrix<double> aR = ElMatrix<double>::Rotation(aTeta.z,aTeta.y,aTeta.x); for (int aY=0 ; aY<3 ; aY++) { for (int aX=0 ; aX<3 ; aX++) { std::cout << aR(aX,aY) << " "; } std::cout << "\n"; } /* std::cout << "Sssz " << aLPMin.size() << "\n"; if ( aLPMin.size()>0) std::cout << "PP00 " << *(aLPMin.begin()) << "\n"; */ }
float MapSearchNode::GetCost(MapSearchNode& successor) { return GetCost(); }
int GetModelCost() const { return GetCost(predictor_list_, target_var_); }
SearchResult Dlite::FindThePath(LocalMap &map, const Map& const_map, EnvironmentOptions options) { opt = options; std::chrono::time_point<std::chrono::system_clock> tstart, end; tstart = std::chrono::system_clock::now(); number_of_steps = 0; current_result.pathlength = 0; Initialize(map); last = start; if(!ComputeShortestPath(map)) std::cout << "OOOPS\n"; else std::cout << "Done\n"; std::cout << current_result.pathlength <<std::endl; while(start->point != goal->point) { Cell jump = start->point; Node min_val = GetMinPredecessor(start, map); path.push_back(*start); if (!min_val.parent) { OPEN.remove_if(start); current_result.pathfound = false; current_result.pathlength = 0; return current_result; } else { current_result.pathlength += GetCost(start->point, min_val.parent->point, map); start = min_val.parent; } min_val = GetMinPredecessor(start, map); while (opt.allowjump && euclid_dist(jump, min_val.parent->point) < radius && start->point != goal->point) { path.push_back(*start); if (!min_val.parent) { OPEN.remove_if(start); current_result.pathfound = false; current_result.pathlength = 0; return current_result; } else { current_result.pathlength += GetCost(start->point, min_val.parent->point, map); start = min_val.parent; } min_val = GetMinPredecessor(start, map); } UpdateVertex(start); Changes changes = map.UpdateMap(const_map, start->point, radius); if (!changes.cleared.empty() && !changes.occupied.empty()) { Km += heuristic(last->point, start->point, opt.metrictype); last = start; } for (auto dam : changes.occupied) { if (NODES.count(vertex(dam, map.height))) { Node* d = &(NODES.find(vertex(dam, map.height))->second); OPEN.remove_if(d); for (auto neighbor: GetSurroundings(d, map)) { //std::cout << "n: " << neighbor->point << std::endl; if (neighbor->point != map.goal && (neighbor->parent->point == dam || CutOrSqueeze(neighbor, d))) { Node min_val = GetMinPredecessor(neighbor, map); if (!min_val.parent) { OPEN.remove_if(neighbor); if(neighbor->point == start->point) { current_result.pathfound = false; current_result.pathlength = 0; return current_result; } } else { neighbor->rhs = min_val.rhs; neighbor->parent = min_val.parent; // std::cout << "changed: " // << neighbor->point << ' ' << neighbor->parent->point << std::endl; UpdateVertex(neighbor); } } } } } for (auto cleared : changes.cleared) { Node new_node(cleared); new_node.rhs = std::numeric_limits<double>::infinity(); new_node.g = std::numeric_limits<double>::infinity(); NODES[vertex(cleared, map.height)] = new_node; Node * cl = &(NODES.find(vertex(cleared, map.height))->second); Node min_val = GetMinPredecessor(cl, map); if (min_val.parent) { cl->rhs = min_val.rhs; cl->parent = min_val.parent; cl->g = min_val.parent->g + GetCost(cl->point, min_val.parent->point, map); UpdateVertex(cl); } else { break; } for (auto neighbor : GetSuccessors(cl, map)) { if (neighbor->rhs > cl->g + GetCost(neighbor->point, cl->point, map)) { neighbor->parent = cl; neighbor->rhs = cl->g + GetCost(neighbor->point, cl->point, map); UpdateVertex(neighbor); } if (neighbor->point.x == cl->point.x || neighbor->point.y == cl->point.y) { Node min_val = GetMinPredecessor(neighbor, map); if (!min_val.parent) { OPEN.remove_if(neighbor); if(neighbor->point == start->point) { current_result.pathfound = false; current_result.pathlength = 0; return current_result; } } else { neighbor->rhs = min_val.rhs; neighbor->parent = min_val.parent; //std::cout << "changed: " // << neighbor->point << ' ' << neighbor->parent->point << std::endl; UpdateVertex(neighbor); } } } } if(ComputeShortestPath(map)){ //std::cout << "ALL OK\n"; continue; } else { std::cout << "NOT OK" << std::endl; if (OPEN.top_key() == Key(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())) { current_result.pathfound = false; current_result.pathlength = 0; break; } } } end = std::chrono::system_clock::now(); current_result.time = static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(end - tstart).count()) / 1000000000; //map.PrintPath(path); current_result.lppath = &path; if (current_result.pathfound) { makeSecondaryPath(); current_result.hppath = &hpath; } //for (auto elem: path) std::cout << elem->point << " "; //std::cout << std::endl; return current_result; }
float GoalDistanceEstimate( const SearchInterface& goal ) { return GetCost( goal ); }
bool NetworkPNL::Save(const char *filename, IXmlWriterExtension *externalExtension, const LegacyDslFileInfo *gnet) { MarkCallFunction("Save", true); static const char fname[] = "Save"; pnl::CContextPersistence saver; pnl::CXMLWriterStd writer; pnl::CGroupObj pnlhGroup; bool bWriteNodeProperty = false; if(!writer.OpenFile(filename)) { ThrowUsingError("can't open file", fname); } if(!m_pWNet->Net().SaveNet(&saver, &pnlhGroup)) { ThrowInternalError("Can't save file", fname); } saver.Put(&pnlhGroup, "WrapperInfo", false); pnl::CGroupObj propertyGroup, propertyNodes, propDiagInfo; propertyGroup.Put(new pnl::CCover<PropertyRealMap >(&m_NetProperty), "NetProperty", true); Vector<String> aNodeName = Graph().Names(); String name; int i, j, k; std::vector<NodeDiagInfo> diagInfo; diagInfo.resize(aNodeName.size()); for(i = 0; i < aNodeName.size(); ++i) { switch (GetDiagType(i)) { case 1: diagInfo[i].m_diagType = "Target"; break; case 2: diagInfo[i].m_diagType = "Observation"; break; case 3: diagInfo[i].m_diagType = "Auxiliary"; break; } diagInfo[i].m_isMandatory = IsMandatory(i); diagInfo[i].m_isRanked = IsRanked(i); diagInfo[i].m_isDefault = GetDefaultOutcome(i); std::vector<bool> targetStates; diagInfo[i].m_isTarget.resize(GetOutcomeCount(i)); for (k = 0; k < GetOutcomeCount(i); ++k) { diagInfo[i].m_isTarget[k] = IsFaultOutcome(i,k); } std::vector<double> costs; costs.resize(0); GetCost(i, costs); diagInfo[i].cost = costs[0]; name = aNodeName[i]; propDiagInfo.Put(new pnl::CCover<NodeDiagInfo >(&diagInfo[i]), name.c_str(), true); j = Graph().INode(aNodeName[i]); if(!m_aNodeProperty[j].size()) { continue; } bWriteNodeProperty = true; name = aNodeName[i]; name << ".property"; propertyNodes.Put(new pnl::CCover<PropertyRealMap >(&m_aNodeProperty[j]), name.c_str(), true); } if(bWriteNodeProperty) { propertyGroup.Put(&propertyNodes, "Nodes", false); } saver.Put(&propertyGroup, "Bridge_PNL_to_GeNIe", false); saver.Put(&propDiagInfo, "DiagnosisInfo", false); if(!saver.SaveViaWriter(&writer)) { ThrowInternalError("Can't save file", fname); } XmlWriterPNLH genieWriter(&writer); externalExtension->WriteExtension(&genieWriter); if(!writer.CloseFile()) { ThrowInternalError("Can't close file", fname); } return true; }
void pgFunction::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) { if (properties) { CreateListColumns(properties); properties->AppendItem(_("Name"), GetName()); properties->AppendItem(_("OID"), GetOid()); properties->AppendItem(_("Owner"), GetOwner()); properties->AppendItem(_("Argument count"), GetArgCount()); properties->AppendItem(_("Arguments"), GetArgListWithNames()); properties->AppendItem(_("Signature arguments"), GetArgSigList()); if (!GetIsProcedure()) properties->AppendItem(_("Return type"), GetReturnType()); properties->AppendItem(_("Language"), GetLanguage()); properties->AppendYesNoItem(_("Returns a set?"), GetReturnAsSet()); if (GetLanguage().IsSameAs(wxT("C"), false)) { properties->AppendItem(_("Object file"), GetBin()); properties->AppendItem(_("Link symbol"), GetSource()); } else properties->AppendItem(_("Source"), firstLineOnly(GetSource())); if (GetConnection()->BackendMinimumVersion(8, 3)) { properties->AppendItem(_("Estimated cost"), GetCost()); if (GetReturnAsSet()) properties->AppendItem(_("Estimated rows"), GetRows()); } properties->AppendItem(_("Volatility"), GetVolatility()); if (GetConnection()->BackendMinimumVersion(9, 2)) properties->AppendYesNoItem(_("Leak proof?"), GetIsLeakProof()); properties->AppendYesNoItem(_("Security of definer?"), GetSecureDefiner()); properties->AppendYesNoItem(_("Strict?"), GetIsStrict()); if (GetConnection()->BackendMinimumVersion(8, 4)) properties->AppendYesNoItem(_("Window?"), GetIsWindow()); size_t i; for (i = 0 ; i < configList.GetCount() ; i++) { wxString item = configList.Item(i); properties->AppendItem(item.BeforeFirst('='), item.AfterFirst('=')); } properties->AppendItem(_("ACL"), GetAcl()); properties->AppendYesNoItem(_("System function?"), GetSystemObject()); properties->AppendItem(_("Comment"), firstLineOnly(GetComment())); if (!GetLabels().IsEmpty()) { wxArrayString seclabels = GetProviderLabelArray(); if (seclabels.GetCount() > 0) { for (unsigned int index = 0 ; index < seclabels.GetCount() - 1 ; index += 2) { properties->AppendItem(seclabels.Item(index), seclabels.Item(index + 1)); } } } } }
wxString pgFunction::GetSql(ctlTree *browser) { if (sql.IsNull()) { wxString qtName = GetQuotedFullIdentifier() + wxT("(") + GetArgListWithNames() + wxT(")"); wxString qtSig = GetQuotedFullIdentifier() + wxT("(") + GetArgSigList() + wxT(")"); sql = wxT("-- Function: ") + qtSig + wxT("\n\n") + wxT("-- DROP FUNCTION ") + qtSig + wxT(";") + wxT("\n\nCREATE OR REPLACE FUNCTION ") + qtName; // Use Oracle style syntax for edb-spl functions if (GetLanguage() == wxT("edbspl") && GetProcType() == 2) { sql += wxT("\nRETURN "); sql += GetReturnType(); sql += wxT(" AS"); if (GetSource().StartsWith(wxT("\n"))) sql += GetSource(); else sql += wxT("\n") + GetSource(); } else { sql += wxT("\n RETURNS "); if (GetReturnAsSet() && !GetReturnType().StartsWith(wxT("TABLE"))) sql += wxT("SETOF "); sql += GetReturnType(); sql += wxT(" AS\n"); if (GetLanguage().IsSameAs(wxT("C"), false)) { sql += qtDbString(GetBin()) + wxT(", ") + qtDbString(GetSource()); } else { if (GetConnection()->BackendMinimumVersion(7, 5)) sql += qtDbStringDollar(GetSource()); else sql += qtDbString(GetSource()); } sql += wxT("\n LANGUAGE ") + GetLanguage() + wxT(" "); if (GetConnection()->BackendMinimumVersion(8, 4) && GetIsWindow()) sql += wxT("WINDOW "); sql += GetVolatility(); if (GetConnection()->BackendMinimumVersion(9, 2) && GetIsLeakProof()) sql += wxT(" LEAKPROOF"); if (GetIsStrict()) sql += wxT(" STRICT"); if (GetSecureDefiner()) sql += wxT(" SECURITY DEFINER"); // PostgreSQL 8.3+ cost/row estimations if (GetConnection()->BackendMinimumVersion(8, 3)) { sql += wxT("\n COST ") + NumToStr(GetCost()); if (GetReturnAsSet()) sql += wxT("\n ROWS ") + NumToStr(GetRows()); } } if (!sql.Strip(wxString::both).EndsWith(wxT(";"))) sql += wxT(";"); size_t i; for (i = 0 ; i < configList.GetCount() ; i++) { if (configList.Item(i).BeforeFirst('=') != wxT("search_path") && configList.Item(i).BeforeFirst('=') != wxT("temp_tablespaces")) sql += wxT("\nALTER FUNCTION ") + qtSig + wxT(" SET ") + configList.Item(i).BeforeFirst('=') + wxT("='") + configList.Item(i).AfterFirst('=') + wxT("';\n"); else sql += wxT("\nALTER FUNCTION ") + qtSig + wxT(" SET ") + configList.Item(i).BeforeFirst('=') + wxT("=") + configList.Item(i).AfterFirst('=') + wxT(";\n"); } sql += wxT("\n") + GetOwnerSql(8, 0, wxT("FUNCTION ") + qtSig) + GetGrant(wxT("X"), wxT("FUNCTION ") + qtSig); if (!GetComment().IsNull()) { sql += wxT("COMMENT ON FUNCTION ") + qtSig + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n"); } if (GetConnection()->BackendMinimumVersion(9, 1)) sql += GetSeqLabelsSql(); } return sql; }
const char* Abil_bloodreload::GetInfor() { static char temp[64]; sprintf_s(temp,64,"남은 탄환이 없을때 체력 %d을 소모하고 장전가능",GetCost()); return temp; }
GenExpTLVec* CFGEnumeratorSingle::PopulateExpsOfGNCost(const GrammarNode* GN, uint32 Cost, bool Complete) { auto Retval = new GenExpTLVec(); GNCostPair Key(GN, Cost); Done = false; auto Type = GN->GetType(); PushExpansion(GN->ToString()); auto const ExpansionTypeID = GetExpansionTypeID(); auto FPVar = GN->As<GrammarFPVar>(); // The base cases if (FPVar != nullptr) { return MakeBaseExpression<GenFPExpression>(Retval, FPVar->GetOp(), Type, ExpansionTypeID, Cost, Key, Complete); } auto LetVar = GN->As<GrammarLetVar>(); if (LetVar != nullptr) { return MakeBaseExpression<GenLetVarExpression>(Retval, LetVar->GetOp(), Type, ExpansionTypeID, Cost, Key, Complete); } auto Const = GN->As<GrammarConst>(); if (Const != nullptr) { return MakeBaseExpression<GenConstExpression>(Retval, Const->GetOp(), Type, ExpansionTypeID, Cost, Key, Complete); } auto Func = GN->As<GrammarFunc>(); if (Func != nullptr) { auto const& Args = Func->GetChildren(); auto Op = Func->GetOp(); const uint32 OpCost = Op->GetCost(); const uint32 Arity = Op->GetArity(); if (Cost < Arity + OpCost) { Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } PartitionGenerator* PG; if (Op->IsSymmetric() && Args[0] == Args[1]) { PG = new SymPartitionGenerator(Cost - OpCost); } else { PG = new PartitionGenerator(Cost - OpCost, Arity); } const uint32 NumPartitions = PG->Size(); for (uint32 i = 0; i < NumPartitions; ++i) { auto Feasible = true; vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr); auto CurPartition = (*PG)[i]; vector<GenExpTLVec::ConstIterator> Begins(Arity); vector<GenExpTLVec::ConstIterator> Ends(Arity); for (uint32 j = 0; j < Arity; ++j) { auto CurVec = GetVecForGNCost(Args[j], CurPartition[j]); if (CurVec == nullptr) { CurVec = PopulateExpsOfGNCost(Args[j], CurPartition[j], false); } if (CurVec->Size() == 0) { Feasible = false; break; } else { ArgExpVecs[j] = CurVec; Begins[j] = CurVec->Begin(); Ends[j] = CurVec->End(); } } if (!Feasible) { continue; } // Iterate over the cross product auto CPGen = new CrossProductGenerator(Begins, Ends, GetPoolForSize(Arity)); for (auto CurArgs = CPGen->GetNext(); CurArgs != nullptr; CurArgs = CPGen->GetNext()) { auto CurExp = new (FuncExpPool->malloc()) GenFuncExpression(static_cast<const InterpretedFuncOperator*>(Op), CurArgs); auto Status = (Complete ? Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) : Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID)); if ((Status & DELETE_EXPRESSION) == 0) { CPGen->RelinquishOwnerShip(); Retval->PushBack(CurExp); NumExpsCached++; } else { FuncExpPool->free(CurExp); } if ((Status & STOP_ENUMERATION) != 0) { Done = true; break; } } delete CPGen; if (Done) { break; } } delete PG; Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } auto Let = GN->As<GrammarLet>(); // We handle this in similar spirit as functions if (Let != nullptr) { auto const& Bindings = Let->GetBindings(); const uint32 NumBindings = Bindings.size(); const uint32 Arity = NumBindings + 1; auto BoundNode = Let->GetBoundExpression(); const uint32 NumLetBoundVars = TheGrammar->GetNumLetBoundVars(); if (Cost < Arity + 1) { Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } // Making a let binding incurs a cost of 1! auto PG = new PartitionGenerator(Cost - 1, Arity); const uint32 NumPartitions = PG->Size(); for (uint32 i = 0; i < NumPartitions; ++i) { auto Feasible = true; vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr); auto CurPartition = (*PG)[i]; vector<GenExpTLVec::ConstIterator> Begins(Arity); vector<GenExpTLVec::ConstIterator> Ends(Arity); uint32 j = 0; uint32* Positions = new uint32[NumBindings]; for (auto it = Bindings.begin(); it != Bindings.end(); ++it) { auto CurVec = GetVecForGNCost(it->second, CurPartition[j]); if (CurVec == nullptr) { CurVec = PopulateExpsOfGNCost(it->second, CurPartition[j], false); } if (CurVec->Size() == 0) { Feasible = false; break; } else { ArgExpVecs[j] = CurVec; Begins[j] = CurVec->Begin(); Ends[j] = CurVec->End(); } Positions[j] = it->first->GetOp()->GetPosition(); ++j; } if (!Feasible) { delete[] Positions; continue; } // Finally, the expression set for the bound expression auto BoundVec = GetVecForGNCost(BoundNode, CurPartition[j]); if (BoundVec == nullptr) { BoundVec = PopulateExpsOfGNCost(BoundNode, CurPartition[j], false); } if (BoundVec->Size() == 0) { // cross product is empty not feasible delete[] Positions; continue; } else { ArgExpVecs[NumBindings] = BoundVec; Begins[NumBindings] = BoundVec->Begin(); Ends[NumBindings] = BoundVec->End(); } // Iterate over the cross product of expressions // The bindings object will be of size of the NUMBER // of let bound vars for the whole grammar auto CPGen = new CrossProductGenerator(Begins, Ends, GetPoolForSize(Arity)); GenExpressionBase const** BindVec = nullptr; auto BindVecPool = GetPoolForSize(NumLetBoundVars); for (auto CurArgs = CPGen->GetNext(); CurArgs != nullptr; CurArgs = CPGen->GetNext()) { // We need to build the binding vector based on the position if (BindVec == nullptr) { BindVec = (GenExpressionBase const**)BindVecPool->malloc(); memset(BindVec, 0, sizeof(GenExpressionBase const*) * NumLetBoundVars); } for (uint32 k = 0; k < NumBindings; ++k) { BindVec[Positions[k]] = CurArgs[k]; } auto CurExp = new (LetExpPool->malloc()) GenLetExpression(BindVec, CurArgs[NumBindings], NumLetBoundVars); auto Status = (Complete ? Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) : Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID)); if ((Status & DELETE_EXPRESSION) == 0) { BindVec = nullptr; Retval->PushBack(CurExp); NumExpsCached++; } else { LetExpPool->free(CurExp); } if ((Status & STOP_ENUMERATION) != 0) { Done = true; break; } } delete CPGen; delete[] Positions; if (Done) { break; } } delete PG; Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } auto NT = GN->As<GrammarNonTerminal>(); if (NT != nullptr) { const vector<GrammarNode*>& Expansions = TheGrammar->GetExpansions(NT); for (auto const& Expansion : Expansions) { auto CurVec = GetVecForGNCost(Expansion, Cost); if (CurVec == nullptr) { CurVec = PopulateExpsOfGNCost(Expansion, Cost, Complete); } Retval->Merge(*CurVec); if (Done) { break; } } Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } // Should NEVER get here throw InternalError((string)"You probably subclassed GrammarNode and forgot to change " + "CFGEnumerator.cpp.\nAt: " + __FILE__ + ":" + to_string(__LINE__)); }