//----------------------------------------------------------------------------------------------- // Called by Ipopt when finished //----------------------------------------------------------------------------------------------- void BonminInterfaceGradients::finalize_solution(TMINLP::SolverReturn status, Index n, const Number* x, Number obj_value) { cout << "IPOPT returned a status indicating "; if ( status == Ipopt::SUCCESS ) cout << "SUCCESS"; else if ( status == Ipopt::MAXITER_EXCEEDED ) cout << "MAXITER_EXCEEDED"; else if ( status == Ipopt::CPUTIME_EXCEEDED ) cout << "CPUTIME_EXCEEDED"; else if ( status == Ipopt::STOP_AT_TINY_STEP ) cout << "STOP_AT_TINY_STEP"; else if ( status == Ipopt::STOP_AT_ACCEPTABLE_POINT ) cout << "STOP_AT_ACCEPTABLE_POINT"; else if ( status == Ipopt::LOCAL_INFEASIBILITY ) cout << "LOCAL_INFEASIBILITY"; else if ( status == Ipopt::USER_REQUESTED_STOP ) cout << "USER_REQUESTED_STOP"; else if ( status == Ipopt::FEASIBLE_POINT_FOUND ) cout << "FEASIBLE_POINT_FOUND"; else if ( status == Ipopt::DIVERGING_ITERATES ) cout << "DIVERGING_ITERATES"; else if ( status == Ipopt::RESTORATION_FAILURE ) cout << "RESTORATION_FAILURE"; else if ( status == Ipopt::ERROR_IN_STEP_COMPUTATION ) cout << "ERROR_IN_STEP_COMPUTATION"; else if ( status == Ipopt::INVALID_NUMBER_DETECTED ) cout << "INVALID_NUMBER_DETECTED"; else if ( status == Ipopt::TOO_FEW_DEGREES_OF_FREEDOM ) cout << "TOO_FEW_DEGREES_OF_FREEDOM"; else if ( status == Ipopt::INVALID_OPTION ) cout << "INVALID_OPTION"; else if ( status == Ipopt::OUT_OF_MEMORY ) cout << "OUT_OF_MEMORY"; else if ( status == Ipopt::INTERNAL_ERROR ) cout << "INTERNAL_ERROR"; else cout << "UNKNOWN_ERROR"; cout << endl; cout << "Writing the final solution to the summary file..." << endl; Case *c = generateCase(n,x); c->setObjectiveValue(-obj_value); p_optimizer->sendBestCaseToRunner(c); }
void SfBall::_initNewGame() { for (std::list<Ball*>::iterator it = _balls.begin(); it != _balls.end(); ++it) delete *it; _balls.clear(); _map->reset(22, 26); _resetMousePosition(); Ball* ball = new Ball(sf::Vector2f(5.5, 5.5), 0.15, _gameWorld); ball->setName("Ball_1"); ball->setSpeed(sf::Vector2f(1, 5) * 0.5f); *_scene << ball; _balls.push_back(ball); Case* current; for (int i = 0; i < 22; ++i) { current = new StandardCase(sf::Vector2f(i, 10), _gameWorld); current->setColor(sf::Color::Yellow); *_scene << current; *_map << current; } for (int i = 6; i < 22; ++i) { current = new StandardCase(sf::Vector2f(i, 5), _gameWorld); current->setColor(sf::Color::Yellow); *_scene << current; *_map << current; } sf::View view = _window->getView(); _playerBar->setPosition(sf::Vector2f(view.getCenter().x, 1)); }
int main(int argc, char **argv){ DBR reasoner = DBR(argv[1],argv[2]); int choice = 0; Case prob = Case(); Dish sol = Dish(); while((choice = mainMenu()) != 3){ switch(choice){ case 1: reasoner.addDish(constructDish()); break; case 2: prob = constructProblem(); sol = reasoner.query(prob); cout << "You should try "; cout << sol.getName() <<endl; if(goodSuggestion()){ reasoner.addCase(Case(prob.getLikes(), prob.getDislikes(), sol)); } break; default: cout << "Unrecognized input!" <<endl; break; } } cout << "Bye!" <<endl; reasoner.save(argv[1],argv[2]); return 0; }
void SfBall::PreSolve(b2Contact *contact, const b2Manifold *oldManifold) { Object* objA = (Object*)contact->GetFixtureA()->GetBody()->GetUserData(); Object* objB = (Object*)contact->GetFixtureB()->GetBody()->GetUserData(); Ball* currentBall = dynamic_cast<Ball*>(objA); Object* currentObject = NULL; if (!currentBall) { currentBall = dynamic_cast<Ball*>(objB); currentObject = objA; } else { currentObject = objB; } if (!currentBall || !currentObject) return ; Case* currentCase = NULL; Wall* currentWall = NULL; Bar* currentBar = NULL; if ((currentCase = dynamic_cast<Case*>(currentObject)) != NULL) { currentCase->contact(this); } else if ((currentWall = dynamic_cast<Wall*>(currentObject)) != NULL) { if (currentWall == _bottomWall) std::cout << "LOOOOSE" << std::endl; } else if ((currentBar = dynamic_cast<Bar*>(currentObject)) != NULL) { } else { contact->SetEnabled(false); return ; } }
Sort* PartieClient::getSort(Position* position, int id_sort) { Case* caseCible = this->getCase(position); if(caseCible == NULL) { return NULL; } return caseCible->getSortId(id_sort); }
bool GestionnaireCollision::collisionMur(const Fantome& fantome, const Case& mur) { if(fantome.estSorti()) { if(mur.getType() != 0 && mur.getType() != 4 && mur.getType() != 5) { return fantome.getSprite().getGlobalBounds().intersects(mur.getRectangle().getGlobalBounds()); } else { return false; } } else { if(mur.getType() != 0 && mur.getType() != 3 && mur.getType() != 4 && mur.getType() != 5) { return fantome.getSprite().getGlobalBounds().intersects(mur.getRectangle().getGlobalBounds()); } else { return false; } } }
Case * AngeAleatoire::choisirUneCase() { int x = 0; int y = 0; int t = maPartie->monDamier->taille; int i, j, n, r; Case * c; // le programme choisit un coup n = 0; // on compte le nombre de coups possibles. for (i=0; i<t; i++) { for (j=0; j<t; j++) { c = maPartie->monDamier->mesCases[i][j]; if ((c->distance(maCase)<=puissance) && !(c->estBouchee()) && (!c->estAnge())) n++; } } r = Alea::engendrer(n); n = 0; // on selectionne un coup aleatoire dans les coups possibles. for (i=0; i<t; i++) { for (j=0; j<t; j++) { c = maPartie->monDamier->mesCases[i][j]; if ((c->distance(maCase)<=puissance) && !(c->estBouchee()) && (!c->estAnge())) if (++n == r) { x = c->getX() + 1; y = c->getY() + 1; } } } return c; }
int main() { int moveNum = 0; freopen("input.txt", "r", stdin); for (int y = 0; y < 8; y++) { scanf("%s", map[y]); } for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { if (map[y][x] == WHITE) { setBit(&nowCase.m_State, x, y, 1); } if (map[y][x] == GOAL) { goalX.push_back(x); goalY.push_back(y); } } } for (;;) { printBoard(); char key = getch(); switch (key) { case 'a': nowCase = nowCase.getNextCase(LEFT); break; case 'w': nowCase = nowCase.getNextCase(UP); break; case 's': nowCase = nowCase.getNextCase(DOWN); break; case 'd': nowCase = nowCase.getNextCase(RIGHT); break; } } return 0; }
void Unite::attaquer(Case c) { if (getJoueur()->getPtAction()<m_AttaqueParDefaut->getPtAction()) { ManquePtAction ex; throw ex; } Case cE = *(getPosition()[0]); if ((abs(c.getX() - cE.getX()) + abs(c.getY() - cE.getY())) <= m_AttaqueParDefaut->getPortee()) { ManquePortee ex; throw ex; } m_AttaqueParDefaut->lancerAttaque(&c); }
void Unite::attaquer(Case c, Attaque* attaque) { if (getJoueur()->getPtAction()<attaque->getPtAction()) { ManquePtAction ex; throw ex; } Case cE = *(getPosition()[0]); if ((abs(c.getX() - cE.getX()) + abs(c.getY() - cE.getY())) <= attaque->getPortee()) { ManquePortee ex; throw ex; } attaque->lancerAttaque(&c); }
bool Classifier::eval(Case &c,PredicateNode &pred) { int attribute=pred.getAttribute(); switch(schema[attribute]->getType()) { case DISCRETE: return c.getDiscrete(attribute)==pred.getIntValue(); case CONTINUOUS: return c.getContinuous(attribute)<= pred.getFloatValue(); } }
bool GestionnaireCollision::collisionMur(const Pacman& pacman, const Case& mur) { // 0 et 4 représente les tile ou l'on peut passer if(mur.getType() != 0 && mur.getType() != 4 && mur.getType() != 5) { return pacman.getSprite().getGlobalBounds().intersects(mur.getRectangle().getGlobalBounds()); } else { return false; } }
//----------------------------------------------------------------------------------------------- // evaluates the model //----------------------------------------------------------------------------------------------- bool LshNomadEvaluator::eval_x(NOMAD::Eval_Point &x, const NOMAD::Double &h_max, bool &count_eval) const { // generating a case from the evaluation point Case *c = generateCase(x); CaseQueue *cq = new CaseQueue(); cq->push_back(c); // sending the case off for evaluation p_optimizer->sendCasesToOptimizer(cq); ///p_optimizer->runCase(c); // extracting the objective x.set_bb_output(0, -c->objectiveValue()); // extracting the constraint values // the constraints in NOMAD must be on the form: c <= 0 for(int i = 0; i < c->numberOfConstraints(); ++i) { double val_input; double val = c->constraintValue(i); double max = p_optimizer->runner()->model()->constraints().at(i)->max(); double min = p_optimizer->runner()->model()->constraints().at(i)->min(); if(val > max) val_input = val - max; else if(val < min) val_input = min - val; else { double u_slack = max - val; double l_slack = val - min; val_input = (u_slack > l_slack) ? -u_slack : -l_slack; } x.set_bb_output(i+1, val_input); } // deleting the case from the heap delete c; delete cq; return true; }
int Case::FinishUpdateLoadedTexturesStatic(void *pData) { UpdateLoadedTexturesParameters *pParams = reinterpret_cast<UpdateLoadedTexturesParameters *>(pData); Case *pThis = pParams->pCase; string newLocationId = pParams->newLocationId; delete pParams; pThis->FinishUpdateLoadedTextures(newLocationId); return 0; }
void ReceptionClient::traitementInfoSort() { char* argument[6] = {NULL}; Sort* sort = NULL; Case* caseCible = NULL; Joueur* proprietaire = NULL; int x = -1, y = -1, duree = -1; unsigned int id = 0; for(int i = 0; i < 6; i++) { argument[i] = strtok (NULL, SEPARATEUR_ELEMENT); } for(int i = 0; i < 6; i++) { if(argument[i] == NULL) { //Info fausse return; } } x = atoi(argument[4]); y = atoi(argument[5]); duree = atoi(argument[3]); id = atoi(argument[1]); sort = this->partie->getSort(Position::fabriquePosition(x, y), id); //Sort inexistant sur la case if(sort == NULL) { sort = UsineSort::fabriqueSort(argument[0]); //Pas de sort de ce nom if(sort == NULL) { return; } proprietaire = this->partie->getJoueur((argument[2])); //Pas de joueur de ce nom if(proprietaire == NULL) { return; } sort->setProprietaire(proprietaire); sort->setId(id); caseCible = this->partie->getCase(Position::fabriquePosition(x, y)); //Pas de case à cette position if(caseCible != NULL) { caseCible->ajouterSort(sort, duree); } } }
Partie::Partie(int t, char a, char d) { monDamier = new Damier(t); gagnee = false; if (a=='h') monAnge = new AngeHumain(this, 1); if (a=='a') monAnge = new AngeAleatoire(this, 1); Case * c = monDamier->mesCases[monDamier->taille/2][monDamier->taille/2]; c->setAnge(monAnge); monAnge->setCase(c); if (d=='h') monDiable = new DiableHumain(this); if (d=='a') monDiable = new DiableAleatoire(this); trait = monAnge; }
void Partie::initialiser() { cout << "\tAnge Humain ou Aleatoire ? (h/a)" << endl; char r; cin >> r; if (r=='h') monAnge = new AngeHumain(this, 1); if (r=='a') monAnge = new AngeAleatoire(this, 1); Case * c = monDamier->mesCases[monDamier->taille/2][monDamier->taille/2]; c->setAnge(monAnge); monAnge->setCase(c); cout << "\tDiable Humain ou Aleatoire ? (h/a)" << endl; cin >> r; if (r=='h') monDiable = new DiableHumain(this); if (r=='a') monDiable = new DiableAleatoire(this); trait = monAnge; }
void Graphics::printRessources(Map *map) { Case *currentCase; std::map<t_ressource, int> currentMap; t_ressource currentRes; for (size_t i = 0; (currentCase = map->getCase(i)) != NULL; i++) { currentMap = currentCase->getRessources(); for (int j = 0; j != 7; j++) { currentRes = (t_ressource)j; if (currentMap[currentRes] > 0) printThisRessourceAtPos(currentRes, currentCase->getPos()); } } }
int main() { clrscr(); Timer t; int index; Case C; C.input(); t.start();index = C.Horspool_Machine();t.stop(); if(index == -1) cout << "\nMatch couldn't be found\n"; else cout << "\nMatch found at position "<< (index + 1) <<"\n"; cout << "\nTime taken for this is : "<< t.time() <<" seconds\n"; getch(); return 0; }
//----------------------------------------------------------------------------------------------- // generates a case with the starting point variable values for int and bin types //----------------------------------------------------------------------------------------------- Case* IpoptOptimizer::generateStartingPoint() { Case *c = new Case(); // integer variables for(int i = 0; i < runner()->model()->integerVariables().size(); ++i) { c->addIntegerVariableValue(runner()->model()->integerVariableValue(i)); } // binary variables for(int i = 0; i < runner()->model()->binaryVariables().size(); ++i) { c->addBinaryVariableValue(runner()->model()->binaryVariableValue(i)); } return c; }
//----------------------------------------------------------------------------------------------- // generates a case from an Eval_Point //----------------------------------------------------------------------------------------------- Case* LshNomadEvaluator::generateCase(const NOMAD::Eval_Point &x) const { Case *c = new Case(); int var_num = 0; for(int i = 0; i < p_optimizer->runner()->model()->realVariables().size(); ++i) { c->addRealVariableValue(x[var_num].value()); ++var_num; } return c; }
void GameForm::updateCaseDisplay(int caseId) { Case* currentCase = Game::getInstance()->getCase(caseId); int value = currentCase->getValue(); Osp::Base::String label= ""; if(value >0 && value <= _valueMax) { if(currentCase->isFixed()) _buttons[caseId]->SetTextColor(Osp::Graphics::Color::COLOR_RED); else _buttons[caseId]->SetTextColor(Osp::Graphics::Color::COLOR_BLUE); label.Insert(value,0); } _buttons[caseId]->SetText(label); }
bool DiableHumain::verifier(int x,int y){ bool ok=true; Case * c; if ((x>0) && (y>0) && (x<=maPartie->monDamier->taille)&& (y<=maPartie->monDamier->taille)) { ok = true; c = maPartie->monDamier->mesCases[x-1][y-1]; if (c->estBouchee()){ cout << "Erreur: case bouchee." << endl; ok = false; } if (c->estAnge()) { cout << "Erreur: case occupee par l'ange." << endl; ok = false; } } else ok = false; return ok; }
Case* CaseBuilder::construct() { Q_ASSERT(m_executable); QFileInfo exeLocation(m_executable->location().toLocalFile()); QString cazeName = m_executable->name(); if (!m_suite.isEmpty() && cazeName.startsWith(m_suite + '-')) { QStringList spl = cazeName.split('-'); Q_ASSERT(spl.count() > 1); spl.removeFirst(); cazeName = spl.join("-"); } Case* caze = new Case(cazeName, exeLocation); caze->setExecutable( m_executable ); Executable* exe = m_executable; //exe->setLocation(KUrl(exeLocation.absoluteFilePath())); m_executable->setCase(caze); exe->setOutputParser( new OutputParser); QStringList exeFunctionOut = m_executable->fetchFunctions(); bool success = false; foreach(QString line, exeFunctionOut) { //krazy:exclude=foreach if (line.endsWith(QLatin1String("()")) && !line.contains(QLatin1String(" "))) { // recognize this as a legit qtest function output line line.chop(2); // remove "()" Command* foo = new Command(line, caze); caze->addChild(foo); success = true; } else { // garbage if (!line.isEmpty()) { kDebug() << "Garbage line:\n" << line; } } } if (success) { return caze; } else { delete caze; return 0; } }
void Unite::deplacer(Case c) { Case nouveau = deplacement(c); if (c.getX()!=nouveau.getX() && c.getY()!=nouveau.getY() && !nouveau.isOccupee()) { nouveau.setCase(this); //Rajout de void setCase(Unite unite); -> Test de si la case n'est pas occup�, puis mettre a jour la case // appel d'une exception si la case est occup� (Pour saut� l'instruction suivante) // ou avec un booleen, je ne sais pas // Nicolas :-D c.setCase(NULL); // mettre a 0 la case } else { cout << "case prise"<<endl; } }
void Etat::interaction(Case& c){ switch(c.getInteraction()){ case 1:{ interface->setEtat(&interface->ainvs); interface->affichage(); break; } case 2:{ cout << "La porte est fermée" << endl; break; } case 3:{ interface->setEtat(&interface->adial); interface->affichage(); break; } } }
void Jeu::tourJoueur(Joueur* j){ pair<Joueur*,int> pairetmp; cout << "debut du tour." << endl; Case* ct; Case* tmp; //on rajoute un au compteur de jouer du joueur j->setJouer(j->getJouer()+1); //s'il peut jouer et qu'il n'a pas gagné, on lance son tour while((j->getJouer())>0 && !joueurAGagne(j)){ int choix = j->choixPions(); pairetmp = make_pair(j,choix); //Le joueur fait son choix de pions et on vérifie que c'est vraiment un pion et qu'il n'est pas en fin //Ici, le joueur peut choisir 0 s'il veut choisir après le lancer de dé while(choix<0 || choix>j->getNombrePions() || (choix!=0 && plateau.estEnFin(placementpions.find(pairetmp)->second))){ choix = j->choixPions(); pairetmp = make_pair(j,choix); } int lancer = j->choixDeplacement(); cout << "le lancer vaut " << lancer << endl; //Si le joueur n'a toujours pas fait son choix, on lui redemande de choisir while(choix<1 || choix>j->getNombrePions() || plateau.estEnFin(placementpions.find(pairetmp)->second)){ choix = j->choixPions(); pairetmp = make_pair(j,choix); } ct = placementpions.find(pairetmp)->second; //une fois la case du pions trouvée, on fait avancer le pion tmp = j->avancerPion(ct, lancer); //on enlève un pion à l'ancienne case ct->setNombrePions(ct->getNombrePions()-1); //on supprime le lien entre pion et case pour créer le nouveau lien placementpions.erase(placementpions.find(pairetmp)); placementpions.insert(make_pair(pairetmp,tmp)); //on rajoute un pion à la nouvelle case tmp->setNombrePions(tmp->getNombrePions()+1); cout << "le pion est à la case " << tmp->getNumeroCase() << endl; cout << "peut-il rejouer ? " << j->getJouer() << endl; string k; afficher(); getline(cin,k); } }
void BruteForceFinder::Worker::solution_found(size_t insert_place, const Case& _case) { Insertion& insertion = this->solving_step.back(); insertion.insert_place = insert_place; auto insert_place_mask = insertion.skeleton.get_insert_place_mask(insert_place); for (const Algorithm& algorithm: _case.algorithm_list()) { Insertion& insertion = this->solving_step.back(); insertion.insertion = &algorithm; if (!insertion.skeleton.is_worthy_insertion( algorithm, insert_place, insert_place_mask, this->finder.fewest_moves )) { continue; } this->solving_step.push_back({ insertion.skeleton.insert(algorithm, insert_place).first, }); this->update_fewest_moves(); this->solving_step.pop_back(); } }
void visitSwitchStatement(SwitchStatement *node) override { prefix(); fprintf(fp_, "[ SwitchStatement\n"); indent(); node->expression()->accept(this); for (size_t i = 0; i < node->cases()->length(); i++) { Case *c = node->cases()->at(i); c->expression()->accept(this); if (c->others()) { for (size_t j = 0; j < c->others()->length(); j++) c->others()->at(j)->accept(this); } indent(); c->statement()->accept(this); unindent(); } if (node->defaultCase()) node->defaultCase()->accept(this); unindent(); }
void Case::copy(const Case kase){//DONE setTouche(kase.getTouche()); setBateau(kase.getBateau()); }