• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cons函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

int
main(int argc)
{


	IloEnv   env;
	try {
		IloModel model(env);

		NumVarMatrix varOutput(env, J + current);
		NumVar3Matrix varHelp(env, J + current);
		Range3Matrix cons(env, J + current);
		for (int j = 0; j <J + current; j++){
			varOutput[j] = IloNumVarArray(env, K);
			varHelp[j] = NumVarMatrix(env, K);
			cons[j] = RangeMatrix(env, K);
			for (int k = 0; k < K; k++){
				varOutput[j][k] = IloNumVar(env, 0.0, IloInfinity);
				varHelp[j][k] = IloNumVarArray(env, L);
				cons[j][k] = IloRangeArray(env, C);
				for (int l = 0; l < L; l++){
					varHelp[j][k][l] = IloNumVar(env, 0.0, IloInfinity);
				}
				if (j > current){
					cons[j][k][0] = IloRange(env, 0.0, 0.0);//will be used to express equality of varOutput, constraint (0)
					cons[j][k][1] = IloRange(env, 0.0, IloInfinity);// constraint (1)
					cons[j][k][2] = IloRange(env, -IloInfinity, T[j] - Tdc - Tblow[j] - Tslack);// constraint (2)
					cons[j][k][3] = IloRange(env, Tfd[k], Tfd[k]);// constraint (3)
					cons[j][k][4] = IloRange(env, 0.0, IloInfinity);// constraint (4)
					cons[j][k][5] = IloRange(env, Tdf[k], IloInfinity);// constraint (5)
					cons[j][k][6] = IloRange(env, T[j - a[k]] + Tcd, T[j - a[k]] + Tcd);// constraint (6)
					cons[j][k][7] = IloRange(env, TlossD[k], IloInfinity);// constraint (7)
					cons[j][k][8] = IloRange(env, TlossF[k], IloInfinity);// constraint (8)
				}
			}
		}

		populatebynonzero(model, varOutput, varHelp, cons);

		IloCplex cplex(model);

		// Optimize the problem and obtain solution.
		if (!cplex.solve()) {
			env.error() << "Failed to optimize LP" << endl;
			throw(-1);
		}

		IloNumArray vals(env);
		IloNumVar val(env);

		//vars to save output
		double TimeAvailable[J][K];
		double TimeInstances[J][K][L];
		double LK103[J][2];


		env.out() << "Solution status = " << cplex.getStatus() << endl;
		env.out() << "Solution value  = " << cplex.getObjValue() << endl;
		for (int j = current; j < current + J; ++j)
		{
			cplex.getValues(vals, varOutput[j]);
			env.out() << "Seconds for load "<<j<<"       = " << vals << endl;
			/*for (int k = 0; k < K; k++){
				TimeAvailable[j][k] = cplex.getValue(varOutput[j][k]);
			}*/
		}
		for (int j = current; j < current + J; j++){
			for (int k = 0; k < K; k++){
				cplex.getValues(vals, varHelp[j][k]);
				env.out() << "Time instances for spoon "<<k<<" in load "<<j<<" = " << vals << endl;
				/*for (int l = 0; l < L; l++){
					TimeInstances[j][k][l] = cplex.getValue(varHelp[j][k][l]);
				}*/
			}
		}

		for (int j = current + 2; j < J + current; j++){
			LK103[j][0] = TimeInstances[j - 2][0][0];
			LK103[j][1] = TimeInstances[j][0][5];
			env.out() << "LK103, load " << j << " : " << LK103[j][1]-LK103[j][0] << endl;
		}
		/*cplex.getSlacks(vals, cons);
		env.out() << "Slacks        = " << vals << endl;
		cplex.getDuals(vals, cons);
		env.out() << "Duals         = " << vals << endl;
		cplex.getReducedCosts(vals, varOutput);
		env.out() << "Reduced Costs = " << vals << endl;*/

		cplex.exportModel("lpex1.lp");
	}
	catch (IloException& e) {
		cerr << "Concert exception caught: " << e << endl;
	}
	catch (...) {
		cerr << "Unknown exception caught" << endl;
	}

	env.end();
	cin.get();
	return 0;
//.........这里部分代码省略.........
开发者ID:ardgrauw,项目名称:Thesis,代码行数:101,代码来源:eerstewerkend.cpp


示例2: AddOpt

 public: Val AddOpt(Val ty)
     { ASSERT(nil != ty); m_opts = cons(ty, m_opts); return ty; }
开发者ID:eval1749,项目名称:evita-common-lisp,代码行数:2,代码来源:ty_04_values.cpp


示例3: liste_test1

liste liste_test1 ()
{
  return cons (1, cons (2, cons (3, cons (4, l_vide ())))) ;
}
开发者ID:BriceSD,项目名称:APL3,代码行数:4,代码来源:test_liste.c


示例4: TYPE

/* Evaluate object 
 * NULL return value means Nothing
 */
object *eval(object *obj, env_hashtable *env)
{
    object *cur, *eobj, 
        *last_pair, *t,
        *ecar, *ecdr;
    
    if (!obj)
        return NULL;
    
    /* Detect syntatic construction */
    if (TYPE(obj) == OBJ_PAIR &&
        TYPE(CAR(obj)) == OBJ_SYMBOL) {
        t = CAR(obj);
        if (strcmp("lambda", STR(t)) == 0) {
            t = CDDR(obj);
            t = cons(symbol("begin"), t);
            eobj = compound_procedure(CADR(obj), t, env);
            return eobj;
        } else if (strcmp("define", STR(t)) == 0) {
            eobj = eval(CADDR(obj), env);
            env_hashtable_insert(env, STR(CADR(obj)), eobj);
            return NULL; /* Not error, just nothing */
        } else if (strcmp("begin", STR(t)) == 0) {
            obj = CDR(obj);
            eobj = NULL; /* Not error, just nothing */
            while (obj != null_object) {
                eobj = eval(CAR(obj), env);
                obj = CDR(obj);
            }
            return eobj;
        } else if (strcmp("apply", STR(t)) == 0) {
            eobj = eval(CADR(obj), env);
            t = eval(CADDR(obj), env);
            return apply(eobj, t);
        } else if (strcmp("quote", STR(t)) == 0) {
            return CADR(obj);
        }
    }
    
    /* Object evaluation */
    switch (TYPE(obj)) {
        case OBJ_NUMBER:
        case OBJ_BOOLEAN:
            return obj;
        case OBJ_SYMBOL:
            return env_hashtable_find(env, STR(obj));
        case OBJ_PAIR:
            cur = obj;
            eobj = null_object;
            last_pair = NULL;
            
            while (cur != null_object && 
                   TYPE(cur) == OBJ_PAIR) {
                t = cons(eval(CAR(cur), env), null_object);
                if (!last_pair)
                    eobj = t;
                else
                    CDR(last_pair) = t;
                last_pair = t;
                
                cur = CDR(cur);
            }
            
            ecar = CAR(eobj);
            ecdr = CDR(eobj);
            
            return apply(ecar, ecdr);
        default:
            return NULL;
    }
}
开发者ID:Nafanya,项目名称:Scheme,代码行数:74,代码来源:eval.c


示例5: cons

Value
Parser::quoted(Symbol *quote)
{
	return cons(quote, cons(parse(), NIL));
}
开发者ID:shaurz,项目名称:amp,代码行数:5,代码来源:parse.cpp


示例6: prepareRule

static Tree prepareRule(Tree rule)
{
  return cons(lmap(preparePattern, hd(rule)), tl(rule));
}
开发者ID:Ace17,项目名称:faust,代码行数:4,代码来源:boxes.cpp


示例7: save2


//.........这里部分代码省略.........
	default:
	    assign(val, exp);		/* self-evaluating */
	    goto fetch_cont;
    }

ev_no_args:
    /* Evaluate an application of a procedure with no arguments. */
    assign(argl, NIL);
    goto apply_dispatch;    /* apply the procedure */

ev_application:
    /* Evaluate an application of a procedure with arguments. */
    assign(unev, cdr(exp));
    assign(argl, NIL);
    mixsave(tailcall,var);
    num2save(val_status,ift_iff_flag);
    save2(didnt_get_output,didnt_output_name);
eval_arg_loop:
    if (unev == NIL) goto eval_args_done;
    assign(exp, car(unev));
    if (exp == Not_Enough_Node) {
	if (NOT_THROWING)
	    err_logo(NOT_ENOUGH, NIL);
	goto eval_args_done;
    }
    save(argl);
    save2(unev,fun);
    save2(ufun,last_ufun);
    save2(this_line,last_line);
    assign(var, var_stack);
    tailcall = -1;
    val_status = 1;
    assign(didnt_get_output,
	   cons_list(0,fun,ufun,this_line,END_OF_LIST));
    assign(didnt_output_name, NIL);
    newcont(accumulate_arg);
    goto eval_dispatch;	    /* evaluate the current argument */

accumulate_arg:
    /* Put the evaluated argument into the argl list. */
    reset_args(var);
    restore2(this_line,last_line);
    restore2(ufun,last_ufun);
    assign(last_call, fun);
    restore2(unev,fun);
    restore(argl);
    while (NOT_THROWING && val == UNBOUND) {
	assign(val, err_logo(DIDNT_OUTPUT, NIL));
    }
    push(val, argl);
    pop(unev);
    goto eval_arg_loop;

eval_args_done:
    restore2(didnt_get_output,didnt_output_name);
    num2restore(val_status,ift_iff_flag);
    mixrestore(tailcall,var);
    if (stopping_flag == THROWING) {
	assign(val, UNBOUND);
	goto fetch_cont;
    }
    assign(argl, reverse(argl));
/* --------------------- APPLY ---------------------------- */
apply_dispatch:
    /* Load in the procedure's definition and decide whether it's a compound
     * procedure or a primitive procedure.
开发者ID:unusual-thoughts,项目名称:freebsd-1.x-ports,代码行数:67,代码来源:eval.c


示例8: append

/*! \brief Concatenate two lists.
 *
 * Create a list by joining two lists together.
 *
 * \param list_a A list to become the head of new list.
 * \param list_b A list to become the tail of new list.
 * \return A list with the elements of \a list_a followed by the
 * elements of \a list_b.
 */
sexp append(sexp list_a, sexp list_b) {
    if (c_bool(null(list_a))) { return list_b; }
    return cons(car(list_a), append(cdr(list_a), list_b));
}
开发者ID:aburry,项目名称:trol,代码行数:13,代码来源:utils.c


示例9: cvc

 bool Porter_Stemmer::cvc(int i) {
   if (i < k0+2 || !cons(i) || cons(i-1) || !cons(i-2)) return false;
   int ch = b[i];
   if (ch == 'w' || ch == 'x' || ch == 'y') return false;
   return true;
 }
开发者ID:Peilin-Yang,项目名称:MinRunQuery,代码行数:6,代码来源:Porter_Stemmer.cpp


示例10: cons

/* nondestructive append */
NODE *append(NODE *a, NODE *b) {
    NODE *result;

    if (a == NIL) return b;
    return cons(car(a), append(cdr(a), b));
}
开发者ID:unusual-thoughts,项目名称:freebsd-1.x-ports,代码行数:7,代码来源:eval.c


示例11: cons

 bool Porter_Stemmer::doublec(int j) {
   if (j < k0+1) return false;
   if (b[j] != b[j-1]) return false;
   return cons(j);
 }
开发者ID:Peilin-Yang,项目名称:MinRunQuery,代码行数:5,代码来源:Porter_Stemmer.cpp


示例12: vowelinstem

 bool Porter_Stemmer::vowelinstem() {
   int i; 
   for (i = k0; i <= j; i++) if (! cons(i)) return true;
   return false;
 }
开发者ID:Peilin-Yang,项目名称:MinRunQuery,代码行数:5,代码来源:Porter_Stemmer.cpp


示例13: listn

static Tree listn (int n, Tree e)
{
	return (n<= 0) ? gGlobal->nil : cons(e, listn(n-1,e));
}
开发者ID:FlatIO,项目名称:faudiostream,代码行数:4,代码来源:eval.cpp


示例14: evalRuleList

/**
 * Evaluates each rule of the list
 */
static Tree	evalRuleList(Tree rules, Tree env)
{
    //cerr << "evalRuleList "<< *rules << " in " << *env << endl;
	if (isNil(rules)) return gGlobal->nil;
	else return cons(evalRule(hd(rules), env), evalRuleList(tl(rules), env));
}
开发者ID:FlatIO,项目名称:faudiostream,代码行数:9,代码来源:eval.cpp


示例15: parse_numeric_aggregate

/*
 * No BNF for numeric aggregates - that's defined by the caller.  What
 * this function does is to parse a sequence of numbers separated by the
 * token specified in separator.  If max is zero, any number of numbers
 * will be parsed; otherwise, exactly max numbers are expected.  Base
 * and size tell us how to internalize the numbers once they've been
 * tokenized.
 */
unsigned char *
parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
    int separator, int base, int size)
{
	unsigned char *bufp = buf, *s = NULL;
	int token, count = 0;
	char *val, *t;
	size_t valsize;
	pair c = NULL;

	if (!bufp && *max) {
		bufp = malloc(*max * size / 8);
		if (!bufp)
			error("can't allocate space for numeric aggregate");
	} else
		s = bufp;

	do {
		if (count) {
			token = peek_token(&val, cfile);
			if (token != separator) {
				if (!*max)
					break;
				if (token != RBRACE && token != LBRACE)
					token = next_token(&val, cfile);
				parse_warn("too few numbers.");
				if (token != SEMI)
					skip_to_semi(cfile);
				return (NULL);
			}
			token = next_token(&val, cfile);
		}
		token = next_token(&val, cfile);

		if (token == EOF) {
			parse_warn("unexpected end of file");
			break;
		}

		/* Allow NUMBER_OR_NAME if base is 16. */
		if (token != NUMBER &&
		    (base != 16 || token != NUMBER_OR_NAME)) {
			parse_warn("expecting numeric value.");
			skip_to_semi(cfile);
			return (NULL);
		}
		/*
		 * If we can, convert the number now; otherwise, build a
		 * linked list of all the numbers.
		 */
		if (s) {
			convert_num(s, val, base, size);
			s += size / 8;
		} else {
			valsize = strlen(val) + 1;
			t = malloc(valsize);
			if (!t)
				error("no temp space for number.");
			memcpy(t, val, valsize);
			c = cons(t, c);
		}
	} while (++count != *max);

	/* If we had to cons up a list, convert it now. */
	if (c) {
		bufp = malloc(count * size / 8);
		if (!bufp)
			error("can't allocate space for numeric aggregate.");
		s = bufp + count - size / 8;
		*max = count;
	}
	while (c) {
		pair cdr = c->cdr;
		convert_num(s, (char *)c->car, base, size);
		s -= size / 8;
		/* Free up temp space. */
		free(c->car);
		free(c);
		c = cdr;
	}
	return (bufp);
}
开发者ID:coyizumi,项目名称:cs111,代码行数:90,代码来源:parse.c


示例16: evalRule

/**
 * Evaluates the list of patterns and closure the rhs
 */
static Tree	evalRule(Tree rule, Tree env)
{
    //cerr << "evalRule "<< *rule << " in " << *env << endl;
	return cons(evalPatternList(left(rule), env), right(rule));
}
开发者ID:FlatIO,项目名称:faudiostream,代码行数:8,代码来源:eval.cpp


示例17: while

void SceneObjectCartPole::synchronousUpdate(float dt) {
	if (_ticks >= _ticksPerAction || !getRenderScene()->_renderingEnabled) {
		_ticks = 0;

		std::array<char, _maxBatchSize> buffer;

		std::array<char, 1 + 4 + 4> msg;

		size_t received = 0;
		size_t totalReceived = 0;

		while (totalReceived < msg.size()) {
			_socket->receive(buffer.data(), msg.size() - totalReceived, received);

			for (int i = 0; i < received; i++)
				msg[totalReceived + i] = buffer[i];

			totalReceived += received;
		}

		if (msg[0] == 'A') { // Action
			_action = pge::Vec2f(*reinterpret_cast<float*>(&msg[1]), *reinterpret_cast<float*>(&msg[5]));
		}
		else if (msg[0] == 'R') { // Reset
			_action = pge::Vec2f(*reinterpret_cast<float*>(&msg[1]), *reinterpret_cast<float*>(&msg[5]));

			reset();
		}
		else if (msg[0] == 'C') { // Capture + action
			_action = pge::Vec2f(*reinterpret_cast<float*>(&msg[1]), *reinterpret_cast<float*>(&msg[5]));

			_capture = true;

			if (!getRenderScene()->_renderingEnabled) {
				getRenderScene()->getRenderWindow()->setFramerateLimit(60);
				getRenderScene()->getRenderWindow()->setVerticalSyncEnabled(true);
			}

			getRenderScene()->_renderingEnabled = true;
		}
		else if (msg[0] == 'S') { // Stop capture + action
			_action = pge::Vec2f(*reinterpret_cast<float*>(&msg[1]), *reinterpret_cast<float*>(&msg[5]));

			_capture = false;

			if (!_show) {
				if (getRenderScene()->_renderingEnabled) {
					getRenderScene()->getRenderWindow()->setFramerateLimit(0);
					getRenderScene()->getRenderWindow()->setVerticalSyncEnabled(false);
				}

				getRenderScene()->_renderingEnabled = false;
			}
		}
		else if (msg[0] == 'X') { // Exit
			getRenderScene()->_close = true;
		}

		_action.x = std::min(1.0f, std::max(-1.0f, _action.x));
		_action.y = std::min(1.0f, std::max(-1.0f, _action.y));
		
		act();

		// Give state and reward (+ capture if is on)

		// Observation (8 values)
		std::vector<float> obs(8);

		btVector3 pos = _pRigidBodyCart->getWorldTransform().getOrigin();
		btVector3 vel = _pRigidBodyCart->getLinearVelocity();
		btQuaternion rot = _pRigidBodyPole->getWorldTransform().getRotation();
		btVector3 angleVel = _pRigidBodyPole->getAngularVelocity();

		pge::Quaternion rotC = cons(rot);
		pge::Vec3f rotE = rotC.getEulerAngles();

		obs[0] = pos.getX();
		obs[1] = pos.getZ();
		obs[2] = vel.getX();
		obs[3] = vel.getZ();
		obs[4] = rotE.x;
		obs[5] = rotE.z;
		obs[6] = angleVel.getX();
		obs[7] = angleVel.getZ();

		// First add reward
		int index = 0;

		*reinterpret_cast<float*>(&buffer[index]) = _reward;

		index += sizeof(float);

		for (int i = 0; i < obs.size(); i++) {
			*reinterpret_cast<float*>(&buffer[index]) = obs[i];

			index += sizeof(float);
		}

		// Reset flag
		*reinterpret_cast<int*>(&buffer[index]) = static_cast<int>(_doneLastFrame);
//.........这里部分代码省略.........
开发者ID:222464,项目名称:PGE,代码行数:101,代码来源:SceneObjectCartPole.cpp


示例18: real_a2sb

static Tree real_a2sb(Tree exp)
{
	Tree abstr, visited, unusedEnv, localValEnv, var, name, body;

	if (isClosure(exp, abstr, unusedEnv, visited, localValEnv)) {

		if (isBoxIdent(abstr)) {
			// special case introduced with access and components
			Tree result = a2sb(eval(abstr, visited, localValEnv));

			// propagate definition name property when needed
			if (getDefNameProperty(exp, name))	setDefNameProperty(result, name);
			return result;

		} else if (isBoxAbstr(abstr, var, body)) {
			// Here we have remaining abstraction that we will try to 
			// transform in a symbolic box by applying it to a slot

			Tree slot = boxSlot(++gGlobal->gBoxSlotNumber); 
			stringstream s; s << boxpp(var);
			setDefNameProperty(slot, s.str() ); // ajout YO
			
			// Apply the abstraction to the slot
			Tree result = boxSymbolic(slot, a2sb(eval(body, visited, pushValueDef(var, slot, localValEnv))));

			// propagate definition name property when needed
			if (getDefNameProperty(exp, name)) setDefNameProperty(result, name);
			return result;

        } else if (isBoxEnvironment(abstr)) {
            return abstr;
	
		} else {
            evalerror(yyfilename, -1, "a2sb : internal error : not an abstraction inside closure", exp);
            // Never reached...
            return 0;
        }
		
	} else if (isBoxPatternMatcher(exp)) {
		// Here we have remaining PM rules that we will try to 
		// transform in a symbolic box by applying it to a slot
		
		Tree slot = boxSlot(++gGlobal->gBoxSlotNumber); 			
		stringstream s; s << "PM" << gGlobal->gBoxSlotNumber;
		setDefNameProperty(slot, s.str() ); 
		
		// apply the PM rules to the slot and transfoms the result in a symbolic box
		Tree result = boxSymbolic(slot, a2sb(applyList(exp, cons(slot,gGlobal->nil))));

		// propagate definition name property when needed
		if (getDefNameProperty(exp, name)) setDefNameProperty(result, name);
		return result;

    } else if (isBoxWaveform(exp)) {
        // A waveform is always in Normal Form, nothing to evaluate
        return exp;

	} else {
		// it is a constructor : transform each branches
        unsigned int    ar = exp->arity();
		tvec            B(ar);
        bool            modified = false;
		for (unsigned int i = 0; i < ar; i++) {
            Tree b = exp->branch(i);
            Tree m = a2sb(b);
            B[i] = m;
            if (b != m) modified=true;
		}
        Tree r = (modified) ? CTree::make(exp->node(), B) : exp;
        return r;
	}
}
开发者ID:FlatIO,项目名称:faudiostream,代码行数:72,代码来源:eval.cpp


示例19: cons

  tl expr, val;

  expr = cons(tl_s_quote, cons(a, tl_nil));
  val = tl_eval_print(TL expr, env);

  expr = cons(tl_s_quote, cons(cons(a, b), tl_nil));
  val = tl_eval_print(TL expr, env);

  expr = tl_s_cons;
  val = tl_eval_print(TL expr, env);

  expr = cons(tl_s_car, cons(cons(tl_s_quote, cons(expr, tl_nil)), tl_nil));
  val = tl_eval_print(TL expr, env);

  expr = cons(tl_s_cons, 
              cons(
                   cons(tl_s_quote, cons(a, tl_nil)),
                   cons(
                        cons(tl_s_quote, cons(b, tl_nil)),
                        tl_nil)));
  val = tl_eval_print(TL expr, env);

  expr = cons(cons(tl_s_lambda, 
                   cons(cons(a, cons(b, tl_nil)),
                        cons(cons(tl_s_cons, cons(a, cons(b, tl_nil))),
                             tl_nil))),
              cons(tl_i(1),
                   cons(tl_i(2),
                        tl_nil)));
  val = tl_eval_print(TL expr, env);
  
开发者ID:kstephens,项目名称:tl,代码行数:30,代码来源:test.c


示例20: nwires

/**
 * repeat n times a wire
 */
static Tree nwires(int n)
{
	Tree l = gGlobal->nil;
	while (n--) { l = cons(boxWire(), l); }
	return l;
}
开发者ID:FlatIO,项目名称:faudiostream,代码行数:9,代码来源:eval.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cons_getc函数代码示例发布时间:2022-05-30
下一篇:
C++ conoutf函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap