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


C++ cost函数代码示例

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


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

示例1: TEST

TEST(TestSemiGlobalDev, WithBT)
{    
    tdv::BirchfieldCostDev cost(64);
    tdv::SemiGlobalDev sg;

   runStereoTest(
       "../../res/tsukuba512_L.png",
       "../../res/tsukuba512_R.png",
       "tsukuba_btsgdev.png",
       &cost, &sg, false, false);
}
开发者ID:flair2005,项目名称:ThunderVision,代码行数:11,代码来源:testsemiglobal.cpp

示例2: print_range

static void print_range(FILE *fp,tensor P,real MSF,real energy)
{
    int  i;

    fprintf(fp,"%8.3f  %8.3f  %8.3f  %8.3f",
            cost(P,MSF,energy),trace(P)/3,MSF,energy);
    for(i=0; (i<nparm); i++)
        fprintf(fp," %s %10g",esenm[range[i].ptype],range[i].rval);
    fprintf(fp," FF\n");
    fflush(fp);
}
开发者ID:daneeq,项目名称:GromPy,代码行数:11,代码来源:xutils.c

示例3: cost

int QuickBucket::GetCase(xyLoc & l1, xyLoc & l2, xyLoc & g)
{
	abCost cost(DeltaCostCD(l1,l2,g));
	for (int i = 0; i < 6; i ++)
	{
		if (cost.a == A[i] && cost.b == B[i])
		{
			return i;
		}
	}
	return 0;
}
开发者ID:antmd,项目名称:gppc-2013,代码行数:12,代码来源:QuickBucket.cpp

示例4: defined

void RFrame::print(const char* kind) {
#ifndef PRODUCT
#if defined(COMPILER2) || INCLUDE_JVMCI
  int cnt = top_method()->interpreter_invocation_count();
#else
  int cnt = top_method()->invocation_count();
#endif
  tty->print("%3d %s ", _num, is_interpreted() ? "I" : "C");
  top_method()->print_short_name(tty);
  tty->print_cr(": inv=%5d(%d) cst=%4d", _invocations, cnt, cost());
#endif
}
开发者ID:gaoxiaojun,项目名称:dync,代码行数:12,代码来源:rframe.cpp

示例5: cost_grad

VectorU cost_grad(PR2System& sys, const VectorJ& j, const Vector3d& obj, const VectorU& u, const double alpha) {
	VectorU grad;

	MatrixX sigma = .01*MatrixX::Identity();
	sigma.block<3,3>(J_DIM,J_DIM) = 20*Matrix3d::Identity();

	double cost_p, cost_m;
	VectorU u_plus = u, u_minus = u;
	for(int i=0; i < U_DIM; ++i) {
		u_plus = u; u_minus = u;
		u_plus(i) = u(i) + epsilon;
		u_minus(i) = u(i) - epsilon;

		cost_p = cost(sys, j, obj, u_plus, alpha);

		cost_m = cost(sys, j, obj, u_minus, alpha);

		grad(i) = (cost_p - cost_m) / (2*epsilon);
	}
	return grad;
}
开发者ID:gkahn13,项目名称:bsp,代码行数:21,代码来源:old-test-pr2-system.cpp

示例6: main

int main(int, const char * []) {
    IloEnv env;
    try {
        IloInt i,j;
        IloModel model(env);

        IloNumExpr cost(env);
        IloIntervalVarArray allTasks(env);
        IloIntervalVarArray joeTasks(env);
        IloIntervalVarArray jimTasks(env);
        IloIntArray joeLocations(env);
        IloIntArray jimLocations(env);

        MakeHouse(model, cost, allTasks, joeTasks, jimTasks, joeLocations,
                  jimLocations, 0, 0,   120, 100.0);
        MakeHouse(model, cost, allTasks, joeTasks, jimTasks, joeLocations,
                  jimLocations, 1, 0,   212, 100.0);
        MakeHouse(model, cost, allTasks, joeTasks, jimTasks, joeLocations,
                  jimLocations, 2, 151, 304, 100.0);
        MakeHouse(model, cost, allTasks, joeTasks, jimTasks, joeLocations,
                  jimLocations, 3, 59,  181, 200.0);
        MakeHouse(model, cost, allTasks, joeTasks, jimTasks, joeLocations,
                  jimLocations, 4, 243, 425, 100.0);

        IloTransitionDistance tt(env, 5);
        for (i=0; i<5; ++i)
            for (j=0; j<5; ++j)
                tt.setValue(i, j, IloAbs(i-j));

        IloIntervalSequenceVar joe(env, joeTasks, joeLocations, "Joe");
        IloIntervalSequenceVar jim(env, jimTasks, jimLocations, "Jim");

        model.add(IloNoOverlap(env, joe, tt));
        model.add(IloNoOverlap(env, jim, tt));

        model.add(IloMinimize(env, cost));

        /* EXTRACTING THE MODEL AND SOLVING. */
        IloCP cp(model);
        if (cp.solve()) {
            cp.out() << "Solution with objective " << cp.getObjValue() << ":" << std::endl;
            for (i=0; i<allTasks.getSize(); ++i) {
                cp.out() << cp.domain(allTasks[i]) << std::endl;
            }
        } else {
            cp.out() << "No solution found. " << std::endl;
        }
    } catch (IloException& ex) {
        env.out() << "Error: " << ex << std::endl;
    }
    env.end();
    return 0;
}
开发者ID:andreasmattas,项目名称:testcode,代码行数:53,代码来源:sched_sequence.cpp

示例7: doit

bool doit()
{
    // min moves needed to transit to goal state
	int sCost = cost(ss);

    // we could need more moves than that ... try up to 50
	for(int limit = sCost; limit <= 50; limit++){
		bool ok= dfs(0, sCost, limit, sr, sc, ss, 0);
		if (ok) return true; 
	}
	return false;
}
开发者ID:draguraman,项目名称:CompProg,代码行数:12,代码来源:p10181.c

示例8: update_vertex

 auto update_vertex(LpState& s)
 {
     if (s.cell != start)
     {
         auto minimum = huge();
         for (auto neighbour : valid_neighbours_of(s.cell))
             minimum = min(minimum, (at(neighbour).g + cost()));
         s.r = minimum;
     }
     q.remove(s.cell);
     if (s.g != s.r) q.push(s.cell);
 }
开发者ID:adammasyk,项目名称:Path-Planning,代码行数:12,代码来源:lifelong_planning.hpp

示例9: cost

void action_t::consume_resource()
{
  resource_consumed = cost();

  if ( sim -> debug )
    log_t::output( sim, "%s consumes %.1f %s for %s", player -> name(),
                   resource_consumed, util_t::resource_type_string( resource ), name() );

  player -> resource_loss( resource, resource_consumed );

  stats -> consume_resource( resource_consumed );
}
开发者ID:imclab,项目名称:SimcraftGearOptimizer,代码行数:12,代码来源:sc_action.cpp

示例10: run

/**
 * Loop principal del algoritmo Simulated Annealing.
 *
 * @instance  :: Instancia del BACP
 * @iter      :: Numero maximo de iteraciones para una temperatura t_current
 * @t_current :: Temperatura inicial
 * @t_min     :: Temperatura minima (eps)
 * @alpha     :: Velocidad de decaimiento de la temperatura
 */
void run(struct bacp_instance *instance, int iter, float t_current, float t_min, float alpha)
{
  unsigned short int i;
  unsigned short int new_cost;
  unsigned short int *s_c      = instance->period;
  unsigned short int old_cost  = cost(instance);
  unsigned short int best_cost = old_cost;
  unsigned short int *s_best   = copy_solution(instance->period, instance->n_courses);

  instance->period = NULL;
  while (t_current > t_min) {
    i = 0;
    while (++i <= iter) {
      if (instance->period) free(instance->period);

      instance->period = s_c;
      instance->period = neighbour(instance);
      new_cost         = cost(instance);

      if (new_cost < old_cost || (exp(-abs(new_cost - old_cost)/t_current) > aceptar())) {
        free(s_c);
        s_c              = instance->period;
        old_cost         = new_cost;
        instance->period = NULL;
      }

      if ( best_cost > new_cost ) {
        if (s_best) free(s_best);
        s_best    = copy_solution(s_c, instance->n_courses);
        best_cost = new_cost;
      }
    }
    t_current = t_current * alpha;
  }

  if (instance->period) free(instance->period);
  if (s_c) free(s_c);

  instance->period = s_best;
}
开发者ID:mammut,项目名称:bacp-simulated-annealing,代码行数:49,代码来源:simulated-annealing.c

示例11: at

bool DepthMap::filterPushHypothesis(const int x, const int y, const double d, const double sigmaVal)
{
    if (not isValid(x, y)) return false;
    bool matchFound = false;
    bool hypExist = false;
    for(int h = 0; h < hMax; ++h)
    {
        double & d1 = at(x, y, h);
        double & sigma1 = sigma(x, y, h);
        double & cost1 = cost(x, y, h);
        if( d1 == OUT_OF_RANGE )
        {
            if ( h == 0 )
            {
                pushHypothesis(x, y, d, sigmaVal);
                // if(d<1) cout << "Pushing: x: " << x << " y: " << y << " d: " << d << " s: " << sigmaVal << endl;
                return true;
            }
            break;
        }
        else if( (not matchFound) and match(d1, sigma1, d, sigmaVal) )
        {
            filter(d1, sigma1, d, sigmaVal);
            // if(d1<1)
            // {
            //     cout << "After merge: d1: " << d1 << "  s1: " << sigma1 << endl;
            // }
            // cost1 = max(cost1 - 1.0, 0.0);
            cost1 -= 2*COST_CHANGE;
            cost1 = std::max(cost1, 0.0);
            matchFound = true;
            // std::cout << "Merged " << x << " " << y << " " << h << " " << cost1 << endl;
        }
        else
        {
            cost1 += COST_CHANGE; // increase cost for all hypotheses that did not match
        }
    }
    sortHypStack(x, y);
    // if (matchFound) return true;
    //The program reaches this area if no matches were found
    // else return pushHypothesis(x, y, d, sigmaVal);
    return matchFound;
    // else 
    // {
    //     // cout << "Mismatch: " << x << " " << y << " " << d << " " << sigmaVal << endl;
    //     // cout << "\t Options:" << endl;
    //     // for(int h = 0; h < hMax; ++h)
    //     //     cout << "\t" << at(x, y, h) << " " << sigma(x, y, h) << " " << cost(x, y, h) << endl;
    //     return false;
    // }
}
开发者ID:BKhomutenko,项目名称:visgeom,代码行数:52,代码来源:depth_map.cpp

示例12: CmdBuildCanal

/**
 * Build a piece of canal.
 * @param tile end tile of stretch-dragging
 * @param flags type of operation
 * @param p1 start tile of stretch-dragging
 * @param p2 waterclass to build. sea and river can only be built in scenario editor
 * @param text unused
 * @return the cost of this operation or an error
 */
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	WaterClass wc = Extract<WaterClass, 0, 2>(p2);
	if (p1 >= MapSize() || wc == WATER_CLASS_INVALID) return CMD_ERROR;

	/* Outside of the editor you can only build canals, not oceans */
	if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;

	TileArea ta(tile, p1);

	/* Outside the editor you can only drag canals, and not areas */
	if (_game_mode != GM_EDITOR && ta.w != 1 && ta.h != 1) return CMD_ERROR;

	CommandCost cost(EXPENSES_CONSTRUCTION);
	TILE_AREA_LOOP(tile, ta) {
		CommandCost ret;

		Slope slope = GetTileSlope(tile, NULL);
		if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) {
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
		}

		/* can't make water of water! */
		if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue;

		ret = DoCommand(tile, 0, 0, flags | DC_FORCE_CLEAR_TILE, CMD_LANDSCAPE_CLEAR);
		if (ret.Failed()) return ret;
		cost.AddCost(ret);

		if (flags & DC_EXEC) {
			switch (wc) {
				case WATER_CLASS_RIVER:
					MakeRiver(tile, Random());
					break;

				case WATER_CLASS_SEA:
					if (TileHeight(tile) == 0) {
						MakeSea(tile);
						break;
					}
					/* FALL THROUGH */

				default:
					MakeCanal(tile, _current_company, Random());
					break;
			}
			MarkTileDirtyByTile(tile);
			MarkCanalsAndRiversAroundDirty(tile);
		}

		cost.AddCost(_price[PR_BUILD_CANAL]);
	}
开发者ID:ShaunOfTheLive,项目名称:OpenCoasterTycoon,代码行数:61,代码来源:water_cmd.cpp

示例13: Mutation_Kpoint

void Mutation_Kpoint(double *z, double *fz,
				int N_dimension,
				double *theta, double *grid_points, int grid_size,
				double temp, double scl, double *accpr_pop,
				double *z_new){

	int k_old ;
	int k_new ;
	int i;
	int lab_1 ;
	int lab_2 ;

	double fz_new ;
	double rat ;
	double un ;

	self_adj_index_search(&k_old, *fz, grid_points, grid_size) ;

	/* propose a new solution */

	for ( i=1 ; i<=N_dimension ; i++) z_new[i] = z[i] ;

	/*1st dimension*/
	lab_1 = integerrng(1,N_dimension) ;
	un = normalrng()*scl ;
	z_new[lab_1] += un ;

	/*2nd dimension*/
	if ( (uniformrng()<0.5) && (N_dimension>=2) ){
		lab_2 = integerrng(1,N_dimension-1) ;
		if ( lab_2 >= lab_1 ) lab_2++ ;
		un = normalrng()*scl ;
		z_new[lab_2] += un ;
	}

	fz_new = cost( z_new, N_dimension ) ;

	self_adj_index_search(&k_new, fz_new, grid_points, grid_size) ;

	rat = -theta[k_new] -fz_new/temp +theta[k_old] + *fz/temp  ;

	/* Accept reject */

	*accpr_pop = ( (rat>0.0) ? 1.0 : exp( rat ) ) ;

	un = uniformrng() ;
	if ( *accpr_pop>un ){
		*fz = fz_new;
		for ( i = 1 ; i <= N_dimension ; i++) z[i] = z_new[i] ;
	}

}
开发者ID:georgios-stats,项目名称:PISAA_Rastrigin,代码行数:52,代码来源:Mutation_operations.c

示例14: E

int E(int i, int l){
	int j, temp; 
	
	if (i<=l){
		return 0;
	}
	if (l==1){
		return cost(1,i);
	}
	//if (l>1){
		int min=1000000000;
		for(j=1; j<i-1; j++){
			temp = E(j,l-1) + cost(j+1,i);
			//printf("temp= %i \n", temp);
			if(temp<min){
				min = temp;
			}
		}
		return min;
	//}
	
}
开发者ID:jianniskouts,项目名称:ece_ntua,代码行数:22,代码来源:test.c

示例15: costfunction

double costfunction(){
	int i;
	sumsqerr=0,sumerr0=0,sumerr1=0;
    cost();
    for(i=0;i<(int)total_samples;i++){
        sumsqerr+=(err[i]*err[i]);
        sumerr0+=  err[i];
        sumerr1+= (err[i]*x[i]);
        }
	sumsqerr=sumsqerr/(2.0f*(double)total_samples);
//	printf("\nSumSqerr: %lf Sumerr0 %lf Sumerr1: %lf",sumsqerr,sumerr0,sumerr1);
	return sumsqerr;
}
开发者ID:sanjeev309,项目名称:Linear-Regression-using-Gradient-Descent--,代码行数:13,代码来源:main.c


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