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


C++ Objective类代码示例

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


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

示例1: getInitialAlpha

  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;
  }
开发者ID:biddisco,项目名称:Trilinos,代码行数:29,代码来源:ROL_LineSearch.hpp

示例2: run

 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++;
   }
 }
开发者ID:Russell-Jones-OxPhys,项目名称:Trilinos,代码行数:26,代码来源:ROL_BackTracking.hpp

示例3: update

  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();
  }
开发者ID:agrippa,项目名称:Trilinos,代码行数:33,代码来源:ROL_NewtonKrylovStep.hpp

示例4: SendSupply

// 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;
	}
开发者ID:FreeFalcon,项目名称:freefalcon-central,代码行数:33,代码来源:supply.cpp

示例5: run

 // 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));
 }
开发者ID:Russell-Jones-OxPhys,项目名称:Trilinos,代码行数:35,代码来源:ROL_PathBasedTargetLevel.hpp

示例6: GetTarget

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);
	}
开发者ID:FreeFalcon,项目名称:freefalcon-central,代码行数:57,代码来源:brigade.cpp

示例7: RebuildParentsList

// 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;
}
开发者ID:FreeFalcon,项目名称:freefalcon-central,代码行数:12,代码来源:camplist.cpp

示例8: AssignUnit

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;
}
开发者ID:FreeFalcon,项目名称:freefalcon-central,代码行数:53,代码来源:gtm.cpp

示例9: Objective

Objective* Objective::create()
{
    Objective *pRet = new Objective();
    if (pRet)
    {
        pRet->autorelease();
        return pRet;
    }
    else
    {
        CC_SAFE_DELETE(pRet);
        return NULL;
    }
}
开发者ID:larryPersonal,项目名称:Nanhua,代码行数:14,代码来源:Objective.cpp

示例10: AddRunwayCraters

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
	}
}
开发者ID:FreeFalcon,项目名称:freefalcon-central,代码行数:49,代码来源:persist.cpp

示例11: run

 // 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++;
 }
开发者ID:ChiahungTai,项目名称:Trilinos,代码行数:17,代码来源:ROL_IterationScaling.hpp

示例12: get

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;
}
开发者ID:liangdong158,项目名称:acado,代码行数:47,代码来源:ocp_export.cpp

示例13: checkFbc

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;
    }
  }
}
开发者ID:sbmlteam,项目名称:test-suite,代码行数:46,代码来源:testSuiteUtil.cpp

示例14: f

  /** \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();
  }
开发者ID:rainiscold,项目名称:trilinos,代码行数:21,代码来源:ROL_PrimalDualActiveSetStep.hpp

示例15: OnValidObjective

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;
	}
开发者ID:FreeFalcon,项目名称:freefalcon-central,代码行数:18,代码来源:brigade.cpp


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