virtual Real getInitialAlpha(int &ls_neval, int &ls_ngrad, const Real fval, const Real gs, const Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj, BoundConstraint<Real> &con) { Real val = 1.0; if (useralpha_) { val = alpha0_; } else { if (edesc_ == DESCENT_STEEPEST || edesc_ == DESCENT_NONLINEARCG) { Real tol = std::sqrt(ROL_EPSILON); Real alpha = 1.0; // Evaluate objective at x + s updateIterate(*d_,x,s,alpha,con); obj.update(*d_); Real fnew = obj.value(*d_,tol); ls_neval++; // Minimize quadratic interpolate to compute new alpha alpha = -gs/(2.0*(fnew-fval-gs)); val = ((std::abs(alpha) > std::sqrt(ROL_EPSILON)) ? std::abs(alpha) : 1.0); alpha0_ = val; useralpha_ = true; } else { val = 1.0; } } return val; }
void run( Real &alpha, Real &fval, int &ls_neval, int &ls_ngrad, const Real &gs, const Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj, BoundConstraint<Real> &con ) { Real tol = std::sqrt(ROL_EPSILON<Real>()); ls_neval = 0; ls_ngrad = 0; // Get initial line search parameter alpha = LineSearch<Real>::getInitialAlpha(ls_neval,ls_ngrad,fval,gs,x,s,obj,con); // Update iterate LineSearch<Real>::updateIterate(*xnew_,x,s,alpha,con); // Get objective value at xnew Real fold = fval; obj.update(*xnew_); fval = obj.value(*xnew_,tol); ls_neval++; // Perform backtracking while ( !LineSearch<Real>::status(LINESEARCH_BACKTRACKING,ls_neval,ls_ngrad,alpha,fold,gs,fval,*xnew_,s,obj,con) ) { alpha *= rho_; // Update iterate LineSearch<Real>::updateIterate(*xnew_,x,s,alpha,con); // Get objective value at xnew obj.update(*xnew_); fval = obj.value(*xnew_,tol); ls_neval++; } }
void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj, BoundConstraint<Real> &bnd, AlgorithmState<Real> &algo_state ) { Real tol = std::sqrt(ROL_EPSILON<Real>()); Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); // Update iterate algo_state.iter++; x.plus(s); (step_state->descentVec)->set(s); algo_state.snorm = s.norm(); // Compute new gradient if ( useSecantPrecond_ ) { gp_->set(*(step_state->gradientVec)); } obj.update(x,true,algo_state.iter); if ( computeObj_ ) { algo_state.value = obj.value(x,tol); algo_state.nfval++; } obj.gradient(*(step_state->gradientVec),x,tol); algo_state.ngrad++; // Update Secant Information if ( useSecantPrecond_ ) { secant_->updateStorage(x,*(step_state->gradientVec),*gp_,s,algo_state.snorm,algo_state.iter+1); } // Update algorithm state (algo_state.iterateVec)->set(x); algo_state.gnorm = step_state->gradientVec->norm(); }
// This sends supply from s to d, subtracting from losses and adding to it's supply traffic field // Updates values to amount which actually made it. returns 0 if none made it. int SendSupply (Objective s, Objective d, int *supply, int *fuel) { Objective c; PathClass path; int i,l,n,loss,type; if (!*supply && !*fuel) return 0; if (GetObjectivePath(&path,s,d,Foot,s->GetTeam(),PATH_MARINE) < 1) return 0; c = s; loss = 0; AddSupply(s,*supply/10,*fuel/10); for (i=0; i<path.GetLength(); i++) { n = path.GetDirection(i); c = c->GetNeighbor(n); type = c->GetType(); if (type == TYPE_ROAD || type == TYPE_INTERSECT || type == TYPE_RAILROAD || type == TYPE_BRIDGE) { AddSupply(c,*supply/10,*fuel/10); l = c->GetObjectiveSupplyLosses() + 2; // Automatic loss rate of 2% per objective *supply = *supply*(100-l)/100; *fuel = *fuel*(100-l)/100; } if (!*supply && !*fuel) return 0; } return 1; }
// Run Iteration scaled line search void run( Real &alpha, Real &fval, int &ls_neval, int &ls_ngrad, const Real &gs, const Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj, BoundConstraint<Real> &con ) { Real tol = std::sqrt(ROL_EPSILON<Real>()); ls_neval = 0; ls_ngrad = 0; // Update target objective value if ( fval < min_value_ ) { min_value_ = fval; } target_ = rec_value_ - 0.5*delta_; if ( fval < target_ ) { rec_value_ = min_value_; sigma_ = 0.0; } else { if ( sigma_ > bound_ ) { rec_value_ = min_value_; sigma_ = 0.0; delta_ *= 0.5; } } target_ = rec_value_ - delta_; // Get line-search parameter alpha = (fval - target_)/std::abs(gs); // Update iterate LineSearch<Real>::updateIterate(*xnew_,x,s,alpha,con); // Compute objective function value obj.update(*xnew_); fval = obj.value(*xnew_,tol); ls_neval++; // Update sigma sigma_ += alpha*std::sqrt(std::abs(gs)); }
int BrigadeClass::CheckTactic (int tid) { Objective o; if (tid < 1) return 0; if (haveWeaps < 0) { FalconEntity *e; GridIndex x,y,dx,dy; e = GetTarget(); if (Engaged() && !e) SetEngaged(0); if (GetUnitSupply() > 20) haveWeaps = 1; else haveWeaps = 0; GetLocation(&x,&y); o = GetUnitObjective(); ourObjOwner = 0; if (o && o->GetTeam() == GetTeam()) ourObjOwner = 1; if (o) o->GetLocation(&dx,&dy); else GetUnitDestination(&dx,&dy); ourObjDist = FloatToInt32(Distance(x,y,dx,dy)); } if (!CheckUnitType(tid, GetDomain(), GetType())) return 0; if (!CheckTeam(tid,GetTeam())) return 0; if (!CheckEngaged(tid,Engaged())) return 0; if (!CheckCombat(tid,Combat())) return 0; if (!CheckLosses(tid,Losses())) return 0; if (!CheckRetreating(tid,Retreating())) return 0; if (!CheckAction(tid,GetUnitOrders())) return 0; if (!CheckOwned(tid,ourObjOwner)) return 0; if (TeamInfo[GetTeam()]->GetGroundAction()->actionType != GACTION_OFFENSIVE && !CheckRole(tid,0)) return 0; if (!CheckRange(tid,ourObjDist)) return 0; // if (!CheckDistToFront(tid,ourFrontDist)) // return 0; if (!CheckStatus(tid,Broken())) return 0; // if (!CheckOdds(tid,odds)) // return 0; return GetTacticPriority(tid); }
// This recalculates which secondary objectives belong to which primaries // Assumes RebuildObjectiveLists has been called int RebuildParentsList (void){ Objective o; VuListIterator myit(AllObjList); o = GetFirstObjective(&myit); while (o){ o->RecalculateParent(); o = GetNextObjective(&myit); } return 1; }
int GroundTaskingManagerClass::AssignUnit (Unit u, int orders, Objective o, int score) { Objective so,po; POData pod; // SOData sod; if (!u || !o) return 0; #ifdef KEV_GDEBUG AssignedCount[orders]++; #endif Assigned++; // Set local data right now... u->SetAssigned(1); u->SetOrdered(1); u->SetUnitOrders(orders, o->Id()); // Now collect the SO and PO from this objective, if we don't already have them po = so = o; if (!so->IsSecondary() && o->GetObjectiveParent()) po = so = o->GetObjectiveParent(); if (!po->IsPrimary() && so->GetObjectiveParent()) po = so->GetObjectiveParent(); u->SetUnitObjective(o->Id()); u->SetUnitSecondaryObj(so->Id()); u->SetUnitPrimaryObj(po->Id()); // Increment unit count for this primary pod = GetPOData(po); if (pod) pod->ground_assigned[owner] += u->GetTotalVehicles(); /* if (so != po) { sod = GetSOData(so); if (sod) sod->assigned[owner] += u->GetTotalVehicles(); } */ #ifdef KEV_GDEBUG // char name1[128],name2[128]; // GridIndex x,y,ux,uy; // u->GetName(name1,127); // o->GetName(name2,127); // u->GetLocation(&ux,&uy); // o->GetLocation(&x,&y); // MonoPrint("%s (%d) %s -> %s (%d) @ %d,%d - d:%d, s:%d\n",name1,u->GetCampID(),OrderStr[orders],name2,o->GetCampID(),x,y,(int)Distance(ux,uy,x,y),score); #endif return 1; }
Objective* Objective::create() { Objective *pRet = new Objective(); if (pRet) { pRet->autorelease(); return pRet; } else { CC_SAFE_DELETE(pRet); return NULL; } }
void AddRunwayCraters (Objective o, int f, int craters) { // Add a few linked craters // NOTE: These need to be deterministically generated int i,tp,rp; float x1,y1,x,y,xd,yd,r; int rwindex,runway = 0; ObjClassDataType *oc; // Find the runway header this feature belongs to oc = o->GetObjectiveClassData(); rwindex = oc->PtDataIndex; while (rwindex && !runway) { if (PtHeaderDataTable[rwindex].type == RunwayPt) { for (i=0; i<MAX_FEAT_DEPEND && !runway; i++) { if (PtHeaderDataTable[rwindex].features[i] == f) runway = rwindex; } } rwindex = PtHeaderDataTable[rwindex].nextHeader; } // Check for valid runway (could be a runway number or something) if (!runway) return; rp = GetFirstPt(runway); tp = rp + 1; TranslatePointData(o,rp,&xd,&yd); TranslatePointData(o,tp,&x1,&y1); xd -= x1; yd -= y1; // Seed the random number generator srand(o->Id().num_); for (i=0; i<craters; i++) { // Randomly place craters along the runway. r = ((float)(rand()%1000)) / 1000.0F; x = x1 + r*xd + (((float)(rand()%50)) / 50.0F); y = y1 + r*yd + (((float)(rand()%50)) / 50.0F); NewLinkedPersistantObject(MapVisId(VIS_CRATER2), o->Id(), f, x, y); #ifdef DEBUG Persistant_Runway_Craters++; #endif } }
// Run Iteration scaled line search void run( Real &alpha, Real &fval, int &ls_neval, int &ls_ngrad, const Real &gs, const Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj, BoundConstraint<Real> &con ) { Real tol = std::sqrt(ROL_EPSILON); ls_neval = 0; ls_ngrad = 0; // Get line search parameter algo_iter_++; alpha = LineSearch<Real>::getInitialAlpha(ls_neval,ls_ngrad,fval,gs,x,s,obj,con)/algo_iter_; // Update iterate LineSearch<Real>::updateIterate(*xnew_,x,s,alpha,con); // Compute objective function value obj.update(*xnew_); fval = obj.value(*xnew_,tol); ls_neval++; }
returnValue OCPexport::checkConsistency( ) const { // // Consistency checks: // Objective objective; ocp.getObjective( objective ); int hessianApproximation; get( HESSIAN_APPROXIMATION, hessianApproximation ); if ( ocp.hasObjective( ) == true && !((HessianApproximationMode)hessianApproximation == EXACT_HESSIAN && (objective.getNumMayerTerms() == 1 || objective.getNumLagrangeTerms() == 1)) ) { // for Exact Hessian RTI return ACADOERROR( RET_INVALID_OBJECTIVE_FOR_CODE_EXPORT ); } int sensitivityProp; get(DYNAMIC_SENSITIVITY, sensitivityProp); // if( (HessianApproximationMode)hessianApproximation == EXACT_HESSIAN && (ExportSensitivityType) sensitivityProp != THREE_SWEEPS ) { // return ACADOERROR( RET_INVALID_OPTION ); // } DifferentialEquation f; ocp.getModel( f ); // if ( f.isDiscretized( ) == BT_TRUE ) // return ACADOERROR( RET_NO_DISCRETE_ODE_FOR_CODE_EXPORT ); if ( f.getNUI( ) > 0 ) return ACADOERROR( RET_INVALID_ARGUMENTS ); if ( f.getNP( ) > 0 ) return ACADOERRORTEXT(RET_INVALID_ARGUMENTS, "Free parameters are not supported. For the old functionality use OnlineData class."); if ( (HessianApproximationMode)hessianApproximation != GAUSS_NEWTON && (HessianApproximationMode)hessianApproximation != EXACT_HESSIAN ) return ACADOERROR( RET_INVALID_OPTION ); int discretizationType; get( DISCRETIZATION_TYPE,discretizationType ); if ( ( (StateDiscretizationType)discretizationType != SINGLE_SHOOTING ) && ( (StateDiscretizationType)discretizationType != MULTIPLE_SHOOTING ) ) return ACADOERROR( RET_INVALID_OPTION ); return SUCCESSFUL_RETURN; }
void checkFbc(FbcModelPlugin* fbcmodplug, set<string>& components, set<string>& tests, const map<string, vector<double> >& results) { if (fbcmodplug->isSetStrict() && fbcmodplug->getStrict() == false) { tests.insert("fbc:NonStrict"); } List* allElements = fbcmodplug->getAllElements(); for (unsigned int e=0; e<allElements->getSize(); e++) { SBase* element = static_cast<SBase*>(allElements->get(e)); FluxBound* fluxBound; Objective* objective; switch(element->getTypeCode()) { case SBML_FBC_FLUXBOUND: components.insert("fbc:FluxBound"); fluxBound = static_cast<FluxBound*>(element); if (fluxBound->isSetOperation()) { if (fluxBound->getOperation() == "lessEqual") { tests.insert("fbc:BoundLessEqual"); } else if (fluxBound->getOperation() == "greaterEqual") { tests.insert("fbc:BoundGreaterEqual"); } else if (fluxBound->getOperation() == "equal") { tests.insert("fbc:BoundEqual"); } } break; case SBML_FBC_OBJECTIVE: components.insert("fbc:Objective"); objective = static_cast<Objective*>(element); if (objective->isSetType()) { if (objective->getType() == "maximize") { tests.insert("fbc:MaximizeObjective"); } else { tests.insert("fbc:MinimizeObjective"); } } break; case SBML_FBC_FLUXOBJECTIVE: components.insert("fbc:FluxObjective"); break; default: break; } } }
/** \brief Compute the gradient-based criticality measure. The criticality measure is \f$\|x_k - P_{[a,b]}(x_k-\nabla f(x_k))\|_{\mathcal{X}}\f$. Here, \f$P_{[a,b]}\f$ denotes the projection onto the bound constraints. @param[in] x is the current iteration @param[in] obj is the objective function @param[in] con are the bound constraints @param[in] tol is a tolerance for inexact evaluations of the objective function */ Real computeCriticalityMeasure(Vector<Real> &x, Objective<Real> &obj, BoundConstraint<Real> &con, Real tol) { Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); obj.gradient(*(step_state->gradientVec),x,tol); xtmp_->set(x); xtmp_->axpy(-1.0,(step_state->gradientVec)->dual()); con.project(*xtmp_); xtmp_->axpy(-1.0,x); return xtmp_->norm(); }
int OnValidObjective (Unit e, int role, F4PFList nearlist) { VuListIterator vuit(nearlist); Objective bo = GetFirstObjective(&vuit); while (bo && bo->Id() != e->GetUnitObjectiveID()) bo = GetNextObjective(&vuit); if (bo) { GridIndex x,y; e->GetLocation(&x,&y); if (ScorePosition (e, role, 100, bo, x, y, (bo->GetTeam() == e->GetTeam())? 1:0) < -30000) bo = NULL; } if (bo) return 1; return 0; }
int GetTopPriorityObjectives (int team, _TCHAR* buffers[COLLECTABLE_HP_OBJECTIVES]) { Objective o; _TCHAR tmp[80]; int i; for (i=0; i<COLLECTABLE_HP_OBJECTIVES; i++) buffers[i][0] = 0; // JB 010121 if (!TeamInfo[team]) return 0; o = (Objective) vuDatabase->Find(TeamInfo[team]->GetDefensiveAirAction()->actionObjective); if (o && TeamInfo[team]->GetDefensiveAirAction()->actionType == AACTION_DCA) o->GetFullName(tmp,79,FALSE); else ReadIndexedString(300, tmp, 10); AddStringToBuffer(tmp,buffers[0]); o = (Objective) vuDatabase->Find(TeamInfo[team]->GetOffensiveAirAction()->actionObjective); if (o && TeamInfo[team]->GetOffensiveAirAction()->actionType) o->GetFullName(tmp,79,FALSE); else ReadIndexedString(300, tmp, 10); AddStringToBuffer(tmp,buffers[1]); o = (Objective) vuDatabase->Find(TeamInfo[team]->GetGroundAction()->actionObjective); if (o && TeamInfo[team]->GetGroundAction()->actionType < GACTION_MINOROFFENSIVE) o->GetFullName(tmp,79,FALSE); else ReadIndexedString(300, tmp, 10); AddStringToBuffer(tmp,buffers[2]); o = (Objective) vuDatabase->Find(TeamInfo[team]->GetGroundAction()->actionObjective); if (o && TeamInfo[team]->GetGroundAction()->actionType >= GACTION_MINOROFFENSIVE) o->GetFullName(tmp,79,FALSE); else ReadIndexedString(300, tmp, 10); AddStringToBuffer(tmp,buffers[3]); return 4; }
void compute( Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj, BoundConstraint<Real> &bnd, AlgorithmState<Real> &algo_state ) { Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); Real tol = std::sqrt(ROL_EPSILON<Real>()), one(1); // Compute unconstrained step obj.invHessVec(s,*(step_state->gradientVec),x,tol); s.scale(-one); }
void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj, BoundConstraint<Real> &bnd, AlgorithmState<Real> &algo_state ) { Real tol = std::sqrt(ROL_EPSILON<Real>()), one(1); Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); // Update iterate and store previous step algo_state.iter++; d_->set(x); x.plus(s); bnd.project(x); (step_state->descentVec)->set(x); (step_state->descentVec)->axpy(-one,*d_); algo_state.snorm = s.norm(); // Compute new gradient gp_->set(*(step_state->gradientVec)); obj.update(x,true,algo_state.iter); if ( computeObj_ ) { algo_state.value = obj.value(x,tol); algo_state.nfval++; } obj.gradient(*(step_state->gradientVec),x,tol); algo_state.ngrad++; // Update Secant Information secant_->updateStorage(x,*(step_state->gradientVec),*gp_,s,algo_state.snorm,algo_state.iter+1); // Update algorithm state (algo_state.iterateVec)->set(x); if ( useProjectedGrad_ ) { gp_->set(*(step_state->gradientVec)); bnd.computeProjectedGradient( *gp_, x ); algo_state.gnorm = gp_->norm(); } else { d_->set(x); d_->axpy(-one,(step_state->gradientVec)->dual()); bnd.project(*d_); d_->axpy(-one,x); algo_state.gnorm = d_->norm(); } }
void GroundTaskingManagerClass::RequestEngineer (Objective o, int division) { Unit u; o->SetNeedRepair(1); VuListIterator myit(AllParentList); u = GetFirstUnit(&myit); while (u) { if (u->GetTeam() == owner && u->GetDomain() == DOMAIN_LAND && u->GetUnitNormalRole() == GRO_ENGINEER && u->GetUnitDivision() == division && u->GetUnitOrders() != GORD_REPAIR) { u->SetUnitOrders(GORD_REPAIR,o->Id()); return; } u = GetNextUnit(&myit); } // Find the best _free_ engineer to send to this location }
returnValue MultiObjectiveAlgorithm::evaluateObjectives( VariablesGrid &xd_ , VariablesGrid &xa_ , VariablesGrid &p_ , VariablesGrid &u_ , VariablesGrid &w_ , Expression **arg ){ int run1; Grid tmp_grid; ocp->getGrid( tmp_grid ); VariablesGrid *_xd = 0; VariablesGrid *_xa = 0; VariablesGrid *_p = 0; VariablesGrid *_u = 0; VariablesGrid *_w = 0; if( xd_.isEmpty() == BT_FALSE ) _xd = new VariablesGrid(xd_); if( xa_.isEmpty() == BT_FALSE ) _xa = new VariablesGrid(xa_); if( p_.isEmpty() == BT_FALSE ) _p = new VariablesGrid(p_ ); if( u_.isEmpty() == BT_FALSE ) _u = new VariablesGrid(u_ ); if( w_.isEmpty() == BT_FALSE ) _w = new VariablesGrid(w_ ); Objective *obj; for( run1 = 0; run1 < m; run1++ ){ obj = new Objective( tmp_grid ); obj->addMayerTerm(*arg[run1]); OCPiterate xx( _xd, _xa, _p, _u, _w ); obj->evaluate( xx ); obj->getObjectiveValue( result(count,run1) ); delete obj; } count++; if( _xd != 0 ) delete _xd; if( _xa != 0 ) delete _xa; if( _p != 0 ) delete _p ; if( _u != 0 ) delete _u ; if( _w != 0 ) delete _w ; return SUCCESSFUL_RETURN; }
/** \brief Initialize step. This includes projecting the initial guess onto the constraints, computing the initial objective function value and gradient, and initializing the dual variables. @param[in,out] x is the initial guess @param[in] obj is the objective function @param[in] con are the bound constraints @param[in] algo_state is the current state of the algorithm */ void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g, Objective<Real> &obj, BoundConstraint<Real> &con, AlgorithmState<Real> &algo_state ) { Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); // Initialize state descent direction and gradient storage step_state->descentVec = s.clone(); step_state->gradientVec = g.clone(); step_state->searchSize = 0.0; // Initialize additional storage xlam_ = x.clone(); x0_ = x.clone(); xbnd_ = x.clone(); As_ = s.clone(); xtmp_ = x.clone(); res_ = g.clone(); Ag_ = g.clone(); rtmp_ = g.clone(); gtmp_ = g.clone(); // Project x onto constraint set con.project(x); // Update objective function, get value, and get gradient Real tol = std::sqrt(ROL_EPSILON); obj.update(x,true,algo_state.iter); algo_state.value = obj.value(x,tol); algo_state.nfval++; algo_state.gnorm = computeCriticalityMeasure(x,obj,con,tol); algo_state.ngrad++; // Initialize dual variable lambda_ = s.clone(); lambda_->set((step_state->gradientVec)->dual()); lambda_->scale(-1.0); //con.setVectorToLowerBound(*lambda_); // Initialize Hessian and preconditioner Teuchos::RCP<Objective<Real> > obj_ptr = Teuchos::rcp(&obj, false); Teuchos::RCP<BoundConstraint<Real> > con_ptr = Teuchos::rcp(&con, false); hessian_ = Teuchos::rcp( new PrimalDualHessian<Real>(secant_,obj_ptr,con_ptr,algo_state.iterateVec,xlam_,useSecantHessVec_) ); precond_ = Teuchos::rcp( new PrimalDualPreconditioner<Real>(secant_,obj_ptr,con_ptr,algo_state.iterateVec,xlam_, useSecantPrecond_) ); }
int BrigadeClass::ChooseTactic (void) { int priority=0,tid; haveWeaps = -1; tid = GTACTIC_BRIG_SECURE; while (tid < FirstGroundTactic + GroundTactics && !priority) { priority = CheckTactic(tid); if (!priority) tid++; } // Make Adjustments due to tactic if (tid == GTACTIC_BRIG_WITHDRAW) { Objective o; o = GetUnitObjective(); if (!o || !o->IsSecondary()) { // Find a retreat path o = FindRetreatPath(this,3,FIND_SECONDARYONLY); if (o) SetUnitOrders(GORD_RESERVE,o->Id()); // KCK: This will cause the whole brigade to surrender if the first element get's // cutoff and we're withdrawing. So I'm axing it. Instead, we'll just wait until // the element surrenders. // else // CheckForSurrender(); SetOrdered(1); } } if (GetUnitTactic() != tid) SetOrdered(1); SetUnitTactic(tid); #ifdef ROBIN_GDEBUG if (TrackingOn[GetCampID()]) MonoPrint("Brigade %d (%s) chose tactic %s.\n",GetCampID(),OrderStr[GetUnitOrders()],TacticsTable[tid].name); #endif return tid; }
// This only needs to be called at the start of the campaign (after objs loaded) // or if any new objectives have been added int RebuildObjectiveLists(void){ Objective o; POList->Purge(); SOList->Purge(); { // destroy iterator here VuListIterator myit(AllObjList); o = GetFirstObjective(&myit); while (o != NULL){ if (o->IsPrimary()) POList->ForcedInsert(o); if (o->IsSecondary()) SOList->ForcedInsert(o); o = GetNextObjective(&myit); } } CleanupObjList(); return 1; }
void setObjectiveCoefficient(FbcModelPlugin* plugin, Model* model) { if (plugin == NULL || model == NULL) return; Objective* obj = plugin->getActiveObjective(); if (obj == NULL) return; for (unsigned int i = 0; i < obj->getNumFluxObjectives(); ++i) { FluxObjective* fluxObj = obj->getFluxObjective(i); if (fluxObj == NULL) continue; Reaction* reaction = model->getReaction(fluxObj->getReaction()); if (reaction == NULL) continue; KineticLaw* law = reaction->getKineticLaw(); if (law == NULL) continue; LocalParameter* param = law->getLocalParameter("OBJECTIVE_COEFFICIENT"); param->setValue(fluxObj->getCoefficient()); } }
END_TEST START_TEST (test_FbcExtension_read_L3V1V1_defaultNS) { char *filename = safe_strcat(TestDataDirectory, "fbc_example1_defaultNS.xml"); SBMLDocument *document = readSBMLFromFile(filename); fail_unless(document->getPackageName() == "core"); Model *model = document->getModel(); fail_unless(model != NULL); fail_unless(model->getPackageName() == "core"); fail_unless(document->getNumErrors() == 0); // get the fbc plugin FbcModelPlugin* mplugin = static_cast<FbcModelPlugin*>(model->getPlugin("fbc")); fail_unless(mplugin != NULL); fail_unless(mplugin->getNumObjectives() == 1); fail_unless(mplugin->getListOfObjectives()->getPackageName() == "fbc"); Objective* objective = mplugin->getObjective(0); fail_unless(objective->getId() == "obj1"); fail_unless(objective->getType() == "maximize"); fail_unless(objective->getNumFluxObjectives() == 1); fail_unless(objective->getPackageName() == "fbc"); fail_unless(objective->getListOfFluxObjectives()->getPackageName() == "fbc"); FluxObjective* fluxObjective = objective->getFluxObjective(0); fail_unless(fluxObjective->getReaction() == "J8"); fail_unless(fluxObjective->getPackageName() == "fbc"); fail_unless(fluxObjective->getCoefficient() == 1); fail_unless(mplugin->getNumFluxBounds() == 1); fail_unless(mplugin->getListOfFluxBounds()->getPackageName() == "fbc"); FluxBound* bound = mplugin->getFluxBound(0); fail_unless(bound->getId() == "bound1"); fail_unless(bound->getPackageName() == "fbc"); fail_unless(bound->getReaction() == "J0"); fail_unless(bound->getOperation() == "equal"); fail_unless(bound->getValue() == 10); delete document; }
virtual Real getInitialAlpha(int &ls_neval, int &ls_ngrad, const Real fval, const Real gs, const Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj, BoundConstraint<Real> &con) { Real val = 1.0; if (useralpha_) { val = alpha0_; } else { if (edesc_ == DESCENT_STEEPEST || edesc_ == DESCENT_NONLINEARCG) { Real tol = std::sqrt(ROL_EPSILON); Real alpha = 1.0; // Evaluate objective at x + s updateIterate(*d_,x,s,alpha,con); obj.update(*d_); Real fnew = obj.value(*d_,tol); ls_neval++; // Minimize quadratic interpolate to compute new alpha alpha = -gs/(2.0*(fnew-fval-gs)); // Evaluate objective at x + alpha s updateIterate(*d_,x,s,alpha,con); obj.update(*d_); fnew = obj.value(*d_,tol); ls_neval++; // Ensure that sufficient decrease and curvature conditions are satisfied bool stat = status(LINESEARCH_BISECTION,ls_neval,ls_ngrad,alpha,fval,gs,fnew,x,s,obj,con); if ( !stat ) { alpha = 1.0; } val = alpha; } else { val = 1.0; } } return val; }
/** \brief Update step, if successful. This function returns \f$x_{k+1} = x_k + s_k\f$. It also updates secant information if being used. @param[in] x is the new iterate @param[out] s is the step computed via PDAS @param[in] obj is the objective function @param[in] con are the bound constraints @param[in] algo_state is the current state of the algorithm */ void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj, BoundConstraint<Real> &con, AlgorithmState<Real> &algo_state ) { Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); x.plus(s); feasible_ = con.isFeasible(x); algo_state.snorm = s.norm(); algo_state.iter++; Real tol = std::sqrt(ROL_EPSILON); obj.update(x,true,algo_state.iter); algo_state.value = obj.value(x,tol); algo_state.nfval++; if ( secant_ != Teuchos::null ) { gtmp_->set(*(step_state->gradientVec)); } algo_state.gnorm = computeCriticalityMeasure(x,obj,con,tol); algo_state.ngrad++; if ( secant_ != Teuchos::null ) { secant_->update(*(step_state->gradientVec),*gtmp_,s,algo_state.snorm,algo_state.iter+1); } (algo_state.iterateVec)->set(x); }
void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj, BoundConstraint<Real> &con, AlgorithmState<Real> &algo_state ) { Real tol = std::sqrt(ROL_EPSILON<Real>()); Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); // Update iterate and store step algo_state.iter++; x.plus(s); (step_state->descentVec)->set(s); algo_state.snorm = s.norm(); // Compute new gradient obj.update(x,true,algo_state.iter); if ( computeObj_ ) { algo_state.value = obj.value(x,tol); algo_state.nfval++; } obj.gradient(*(step_state->gradientVec),x,tol); algo_state.ngrad++; // Update algorithm state (algo_state.iterateVec)->set(x); algo_state.gnorm = (step_state->gradientVec)->norm(); }
void compute( Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj, BoundConstraint<Real> &bnd, AlgorithmState<Real> &algo_state ) { Real tol = std::sqrt(ROL_EPSILON<Real>()); Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); // Compute projected Newton step // ---> Apply inactive-inactive block of inverse hessian to gradient gp_->set(*(step_state->gradientVec)); bnd.pruneActive(*gp_,*(step_state->gradientVec),x,algo_state.gnorm); obj.invHessVec(s,*gp_,x,tol); bnd.pruneActive(s,*(step_state->gradientVec),x,algo_state.gnorm); // ---> Add in active gradient components gp_->set(*(step_state->gradientVec)); bnd.pruneInactive(*d_,*(step_state->gradientVec),x,algo_state.gnorm); s.plus(gp_->dual()); s.scale(-1.0); }
/** \brief Update step, if successful. Given a trial step, \f$s_k\f$, this function updates \f$x_{k+1}=x_k+s_k\f$. This function also updates the secant approximation. @param[in,out] x is the updated iterate @param[in] s is the computed trial step @param[in] obj is the objective function @param[in] con are the bound constraints @param[in] algo_state contains the current state of the algorithm */ void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj, BoundConstraint<Real> &con, AlgorithmState<Real> &algo_state ) { Real tol = std::sqrt(ROL_EPSILON); Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState(); // Update iterate algo_state.iter++; x.axpy(1.0, s); // Compute new gradient if ( edesc_ == DESCENT_SECANT || (edesc_ == DESCENT_NEWTONKRYLOV && useSecantPrecond_) ) { gp_->set(*(step_state->gradientVec)); } obj.gradient(*(step_state->gradientVec),x,tol); algo_state.ngrad++; // Update Secant Information if ( edesc_ == DESCENT_SECANT || (edesc_ == DESCENT_NEWTONKRYLOV && useSecantPrecond_) ) { secant_->update(*(step_state->gradientVec),*gp_,s,algo_state.snorm,algo_state.iter+1); } // Update algorithm state (algo_state.iterateVec)->set(x); if ( con.isActivated() ) { if ( useProjectedGrad_ ) { gp_->set(*(step_state->gradientVec)); con.computeProjectedGradient( *gp_, x ); algo_state.gnorm = gp_->norm(); } else { d_->set(x); d_->axpy(-1.0,(step_state->gradientVec)->dual()); con.project(*d_); d_->axpy(-1.0,x); algo_state.gnorm = d_->norm(); } } else { algo_state.gnorm = (step_state->gradientVec)->norm(); } }