コード例 #1
0
void bi::ParticleMCMCNetCDFBuffer::create(const long P, const long T) {
  int id, i;
  VarType type;
  Var* var;
  Dim* dim;

  ncFile->add_att(PACKAGE_TARNAME "_schema", "ParticleMCMC");
  ncFile->add_att(PACKAGE_TARNAME "_schema_version", 1);
  ncFile->add_att(PACKAGE_TARNAME "_version", PACKAGE_VERSION);

  /* dimensions */
  nrDim = createDim("nr", T);
  for (i = 0; i < m.getNumDims(); ++i) {
    dim = m.getDim(i);
    nDims.push_back(createDim(dim->getName().c_str(), dim->getSize()));
  }
  npDim = createDim("np", P);

  /* time variable */
  tVar = ncFile->add_var("time", netcdf_real, nrDim);
  BI_ERROR_MSG(tVar != NULL && tVar->is_valid(), "Could not create time variable");

  /* other variables */
  for (i = 0; i < NUM_VAR_TYPES; ++i) {
    type = static_cast<VarType>(i);
    vars[type].resize(m.getNumVars(type), NULL);

    if (type == D_VAR || type == R_VAR || type == P_VAR) {
      for (id = 0; id < (int)vars[type].size(); ++id) {
        var = m.getVar(type, id);
        if (var->hasOutput()) {
          if (type == P_VAR) {
            vars[type][id] = createVar(var, false, true);
          } else {
            vars[type][id] = createVar(var, !var->getOutputOnce(), true);
          }
        }
      }
    }
  }

  llVar = ncFile->add_var("loglikelihood", netcdf_real, npDim);
  BI_ERROR_MSG(llVar != NULL && llVar->is_valid(),
      "Could not create loglikelihood variable");

  lpVar = ncFile->add_var("logprior", netcdf_real, npDim);
  BI_ERROR_MSG(lpVar != NULL && lpVar->is_valid(),
      "Could not create logprior variable");

}
コード例 #2
0
ファイル: B1.cpp プロジェクト: GG31/packages
B1::B1(const devs::DynamicsInit& model,
       const devs::InitEventList& events) :
    extension::DifferenceEquation::Simple(model, events)
{
    b = createVar("b");
    a = createSync("a");
}
コード例 #3
0
ファイル: A2.cpp プロジェクト: mikaelgrialou/packages
//A(t)=B(t-1)+1
A2::A2(const devs::DynamicsInit& model,
       const devs::InitEventList& events) :
    extension::DifferenceEquation::Simple(model, events)
{
    a = createVar("a");
    b = createNosync("b");
}
コード例 #4
0
ファイル: C3.cpp プロジェクト: mikaelgrialou/packages
        C3(const devs::DynamicsInit& model,
           const devs::InitEventList& events) :
	    vle::extension::DifferenceEquation::Simple(model, events)
	    {
		c = createVar("c");
		b = createSync("b");
	    }
コード例 #5
0
ファイル: M.cpp プロジェクト: GG31/ibm
    M(
       const vd::DynamicsInit& init,
       const vd::InitEventList& events)
    : ve::DifferentialEquation(init, events)
    {
        C3 = createVar("C3");
        C1 = createVar("C1");
        DSAT = createVar("DSAT");
        C2 = createVar("C2");


        if (events.exist("p1"))
            p1 = events.getDouble("p1");
        else
            throw vle::utils::ModellingError("Parameter p1 not found");

    }
コード例 #6
0
ファイル: variables1.c プロジェクト: DanIverson/OpenVnmrJ
varInfo *createString(char *n)
{   varInfo  *v;

    if ( (v=createVar(n)) )
    {	v->T.basicType = T_STRING;
	return(v);
    }
    else
	return(NULL);
}
コード例 #7
0
ファイル: Im.cpp プロジェクト: GG31/packages
        Im(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            gamma = events.getDouble("gamma"); //= 0.2
            sigma = events.getDouble("sigma"); // = 0.5

            I = createVar("I");
            E = createExt("E");
        }
コード例 #8
0
ファイル: variables1.c プロジェクト: DanIverson/OpenVnmrJ
varInfo *createReal(char *n)
{   varInfo  *v;

    if ( (v=createVar(n)) )
    {	v->T.basicType = T_REAL;
	return(v);
    }
    else
	return(NULL);
}
コード例 #9
0
        Rm(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            gamma = events.getDouble("gamma"); //= 0.2
            nu  = events.getDouble("nu");// = 0.0

            R = createVar("R");
            S = createExt("S");
            I = createExt("I");
        }
コード例 #10
0
ファイル: Y.cpp プロジェクト: Chabrier/ibm2
    Y(
       const vd::DynamicsInit& init,
       const vd::InitEventList& events)
    : ve::DifferentialEquation(init, events)
    {
        X = createVar("X");
        maturing = createVar("maturing");
        masse = createVar("masse");


        if (events.exist("KS"))
            KS = events.getDouble("KS");
        else
            throw vle::utils::ModellingError("Parameter KS not found");

        if (events.exist("KG"))
            KG = events.getDouble("KG");
        else
            throw vle::utils::ModellingError("Parameter KG not found");

    }
コード例 #11
0
ファイル: LotkaVolterraY.cpp プロジェクト: GG31/packages
        LotkaVolterraY(const vle::devs::DynamicsInit& model,
                       const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            gamma = (events.exist("gamma"))
                ? events.getDouble("gamma") : 0.5;
            delta = (events.exist("delta"))
                ? events.getDouble("delta") : 0.5;


            Y = createVar("Y");
            X = createExt("X");
        }
コード例 #12
0
ファイル: Sm.cpp プロジェクト: GG31/packages
        Sm(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            beta = events.getDouble("beta");// = 0.9
            nu  = events.getDouble("nu");// = 0.0

            S = createVar("S");                  
            E = createExt("E");
            I = createExt("I");
            R = createExt("R");

        }
コード例 #13
0
        LotkaVolterraX(const vle::devs::DynamicsInit& model,
                       const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {

            alpha = (events.exist("alpha"))
                ? events.getDouble("alpha") : 0.5;
            beta = (events.exist("beta"))
                ? events.getDouble("beta") : 0.5;

            X = createVar("X");
            Y = createExt("Y");
        }
コード例 #14
0
void UserConfig::setValue(const std::string& name, const std::string& value)
{
	UserConfigVar *var = findVarByName(name);
	if (!var)
	{
		std::cerr << "Warning: impossible to set value of " <<
			"unknown configuration variable " << name <<
			"\n Creating new variable" << std::endl;
		var = createVar(name, value);
		mChangeFlag = true;
		return;
	}

	if (var->Value != value) mChangeFlag = true;
	var->Value = value;
}
コード例 #15
0
static void parseAVar(bool diamond){
    // it's a valid type
    char buf[256];
    bool autoRange=false;
    float mn=0,mx=0;
    int size;
    RawDataBuffer *b;
    tok.getnextident(buf); // get name
    
    // if diamond, get topic and datum index
    char tname[256];
    int idx;
#if DIAMOND
    if(diamond){
        tok.getnextcheck(T_TOPIC);
        tok.getnextident(tname);
        tok.getnextcheck(T_COMMA);
        idx = tok.getnextint();
        diamondMap[DiamondTopicKey(tname,idx)]=QString(buf);
        diamondapparatus::subscribe(tname);
        if(!diamondSet.contains(tname))
            diamondSet.insert(tname);
    }
#endif    
    size = tok.getnextint(); // and size
    // now get the range
    tok.getnextcheck(T_RANGE);
    switch(tok.getnext()){
    case T_INT:
    case T_FLOAT:
        mn = tok.getfloat();
        tok.getnextcheck(T_TO);
        mx = tok.getnextfloat();
        break;
    case T_AUTO:
        autoRange=true;
        break;
    default:
        throw UnexpException(&tok,"number or 'auto'");
        break;
    }
    b=createVar(T_NAMEFLOAT,buf,size,mn,mx);
    if(autoRange)
        ((DataBuffer<float>*)b)->setAutoRange();
}
コード例 #16
0
ファイル: photo.c プロジェクト: geoffchu/chuffed
	Photo() {

		srand(so.rnd_seed);
//		n_names = 12 + (int) floor((double) rand()/RAND_MAX*4);
//		n_prefs = 24 + (int) floor((double) rand()/RAND_MAX*12);
		n_names = 10 + (int) floor((double) rand()/RAND_MAX*3);
		n_prefs = 20 + (int) floor((double) rand()/RAND_MAX*10);
		prefs = (int*) malloc(2*n_prefs*sizeof(int));
		for (int i = 0; i < 2*n_prefs; i++) prefs[i] = rand()%n_names;

		printf("%d preferences\n", n_prefs);

		// Create vars

		createVars(x, n_names, 1, n_names);
		createVars(f, 2*n_prefs);
		createVar(sat, 0, n_prefs);

		// Post some constraints

    // Map preferences to fulfilment
    for (int i = 0; i < n_prefs; i++) {
			int_rel_reif(x[prefs[2*i+0]], IRT_EQ, x[prefs[2*i+1]], f[2*i], 1);
			int_rel_reif(x[prefs[2*i+0]], IRT_EQ, x[prefs[2*i+1]], f[2*i+1], -1);
    }

    // Sum of fulfilment
		bool_linear(f, IRT_GE, sat);

		all_different(x);

    // Break some symmetries
		int_rel(x[0], IRT_LT, x[1]);

		// Post some branchings

//		branch(x, VAR_INORDER, VAL_MIN);
		branch(x, VAR_DEGREE_MAX, VAL_MIN);

		// Declare output variables (optional)

		optimize(sat, OPT_MAX);

	}
コード例 #17
0
bool UserConfig::loadFile(const std::string& filename)
{
	PHYSFS_file* fileHandle = PHYSFS_openRead(filename.c_str());
	if (!fileHandle)
	{
		throw FileLoadException(filename);
	}

	int fileLength = PHYSFS_fileLength(fileHandle);
	char* fileBuffer = new char[fileLength + 1];
	PHYSFS_read(fileHandle, fileBuffer, 1, fileLength);
	fileBuffer[fileLength] = 0;
	TiXmlDocument configDoc;
	configDoc.Parse(fileBuffer);
	delete[] fileBuffer;
	PHYSFS_close(fileHandle);

	if (configDoc.Error())
	{
		std::cerr << "Warning: Parse error in " << filename;
		std::cerr << "!" << std::endl;
	}

	TiXmlElement* userConfigElem =
		configDoc.FirstChildElement("userconfig");
	if (userConfigElem == NULL)
		return false;
	for (TiXmlElement* varElem =
		userConfigElem->FirstChildElement("var");
		varElem != NULL;
		varElem = varElem->NextSiblingElement("var"))
	{
		std::string name, value;
		const char* c;
		c = varElem->Attribute("name");
		if (c)
			name = c;
		c = varElem->Attribute("value");
		if (c)
			value = c;
		createVar(name, value);
	}
	return true;
}
コード例 #18
0
ファイル: G1.cpp プロジェクト: mikaelgrialou/packages
G1::G1(const devs::DynamicsInit& model,
       const devs::InitEventList& events) :
    extension::DifferenceEquation::Simple(model, events)
{
    g = createVar("g");
}
コード例 #19
0
void parseLinkedVars(bool diamond){
    char buf[256];
    int size,type;
    RawDataBuffer *linkvar,*b;
    if(tok.getnext()!=T_OPREN)
        throw UnexpException(&tok,"( after linked");
    linkedVars.clear();
    for(;;){
        double mn,mx;
        char buf[256];
        // get type
        type = tok.getnext();
        // get name
        tok.getnextident(buf);
        // if diamond, get topic and datum index
        char tname[256];
        int idx;
#if DIAMOND
        if(diamond){
            tok.getnextcheck(T_TOPIC);
            tok.getnextident(tname);
            tok.getnextcheck(T_COMMA);
            idx = tok.getnextint();
            diamondMap[DiamondTopicKey(tname,idx)]=QString(buf);
            if(!diamondSet.contains(tname))
                diamondSet.insert(tname);
            diamondapparatus::subscribe(tname);
        }
#endif
        // now the range
        tok.getnextcheck(T_RANGE);
        mn = tok.getnextfloat();
        tok.getnextcheck(T_TO);
        mx = tok.getnextfloat();
        
        // add to a list!
        linkedVars.append(LinkedVarEntry(buf,type,mn,mx));
        if(tok.getnext()!=T_COMMA){
            tok.rewind();
            break;
        }
    }
    if(tok.getnext()!=T_CPREN)
        throw UnexpException(&tok,") after linked var list");
    if(tok.getnext()!=T_INT)
        throw UnexpException(&tok,"buffer size after linked var list");
    size = tok.getint();
    
    linkvar = NULL;
    for(int i=0;i<linkedVars.size();i++){
        b = createVar(linkedVars[i].type,
                      linkedVars[i].name,
                      size,
                      linkedVars[i].minVal,
                      linkedVars[i].maxVal);
        if(linkvar)
            linkvar->link(b);
        else
            linkvar = b;
    }
}
コード例 #20
0
ファイル: mosp.c プロジェクト: geoffchu/chuffed
	MOSP(int _n, int _m) : n(_n), m(_m) {

		generateInstance();

		createVars(s, n, 0, n-1);
		createVars(e, n, 0, n-1);
		createVars(sb, n, n);
		createVars(eb, n, n);
		createVars(o, n, n);
		createVar(stacks, 0, n);

		// create customer graph
		bool g[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				g[i][j] = false;
				for (int k = 0; k < m; k++) {
					if (a[i][k] && a[j][k]) {
						g[i][j] = true;
						break;
					}
				}
			}
		}

		// AllDiff constraint on e
		all_different(e);

		// Min constraints on s[i]
		for (int i = 0; i < n; i++) {
			vec<IntVar*> x;
			for (int j = 0; j < n; j++) if (g[i][j]) x.push(e[j]);
			minimum(x, s[i]);
		}

		// open constraints
		for (int i = 0; i < n; i++) {
			for (int t = 0; t < n; t++) {
				int_rel_reif(s[i], IRT_LE, t, sb[i][t]);
				int_rel_reif(e[i], IRT_GE, t, eb[i][t]);
				vec<BoolView> x;
				x.push(sb[i][t]);
				x.push(eb[i][t]);
				array_bool_and(x, o[t][i]);
			}
		}

		// stack constraints
		for (int i = 0; i < n; i++) {
			bool_linear(o[i], IRT_LE, stacks);
		}

		// dominance breaking constraints
		vec<vec<BoolView> > r;
		createVars(r, n, n);

		// Find out which stacks can immediately close
		for (int t = 0; t < n; t++) {
			for (int i = 0; i < n; i++) {
				vec<BoolView> a;
				for (int j = 0; j < n; j++) if (g[i][j]) a.push(sb[j][t]);
				a.push(eb[i][t]);
				array_bool_and(a, r[i][t]);
			}
		}

		// If none of the lex better stacks can instantly close
		// and this one can, close it now
		for (int t = 0; t < n-1; t++) {
			for (int i = 0; i < n; i++) {
				vec<BoolView> a, b;
				for (int j = 0; j < i; j++) a.push(r[j][t]);
				b.push(r[i][t]);
				b.push(eb[i][t+1]);
				bool_clause(a, b);
			}
		}

		// branch on end times
		branch(e, VAR_MIN_MIN, VAL_MIN);

		// set optimization target
		optimize(stacks, OPT_MIN);

	}
コード例 #21
0
ファイル: mcppInterface.cpp プロジェクト: Pyomo/pyomo
 void *new_createVar(double lb, double pt, double ub, int count, int index)
 {
     void *ans = createVar(lb, pt, ub, count, index);
     return ans;
 }
コード例 #22
0
ファイル: vm.c プロジェクト: erik/atto
TValue vm_interpret(AttoVM* vm, AttoBlock* block, int start, int argc)
{
    DEBUGF("Interpret block: %d ops\n", block->code->size);
    int error            = 0;
    TValue* max          = (TValue*)(block->code->elements + start + block->code->size);
    TValue *pc_val       = (TValue*)(block->code->elements + start);
    Instruction i        = TV2INST(*pc_val);
    Stack *stack         = &block->stack;
    const char* opcode_names[] = { OPCODE_NAMES };
    const char* op_name = NULL;

    int x;
    for(x = 0; pc_val < max && !error; ++x) {

        op_name = i >= NUM_OPS ? "unknown" : opcode_names[i];

        if(i >= NUM_OPS) {
            ERROR("bad opcode: %d", i);
        }

        DEBUGF("[%d]\t%s (%d)\n", x, op_name, i);
        switch(i) {
        case OP_NOP:
            DISPATCH;
        case OP_POP:
            EXPECT_ON_STACK(1);
            TValue v = pop(stack);
            valueDestroy(&v);
            DISPATCH;
        case OP_DUP: {
            EXPECT_ON_STACK(1);
            TValue v = pop(stack);
            push(stack, v);
            push(stack, v);
            DISPATCH;
        }
        case OP_SWAP: {
            EXPECT_ON_STACK(2);
            TValue f = pop(stack);
            TValue s = pop(stack);
            push(stack, f);
            push(stack, s);
            DISPATCH;
        }
        case OP_ADD:
        case OP_SUB:
        case OP_MUL:
        case OP_DIV:
        case OP_MOD:
        case OP_POW: {
            EXPECT_ON_STACK(2);
            TValue b = pop(stack);
            TValue a = pop(stack);
            TValue res = MathOp(i, a, b);

            push(stack, res);

            DISPATCH;
        }
        case OP_OR:
        case OP_AND:
        case OP_XOR: {
            EXPECT_ON_STACK(2);
            TValue b = pop(stack);
            TValue a = pop(stack);
            TValue res = BitwiseOp(i, a, b);

            push(stack, res);

            DISPATCH;
        }
        case OP_NOT: {
            EXPECT_ON_STACK(1);
            TValue a = pop(stack);
            push(stack, createNumber(~(long)TV2NUM(a)));
            DISPATCH;
        }
        case OP_EQ:
        case OP_LT:
        case OP_GT:
        case OP_LTE:
        case OP_GTE:
        case OP_CMP: {
            EXPECT_ON_STACK(2);
            TValue b = pop(stack);
            TValue a = pop(stack);
            TValue res = ComparisonOp(i, a, b);

            push(stack, res);

            DISPATCH;
        }
        case OP_IF: {
            EXPECT_ON_STACK(1);
            TValue t = pop(stack);
            if(boolValue(t)) {
                NEXTINST;
            }
            DISPATCH;
        }
        case OP_JMP: {
            EXPECT_ON_STACK(1);
            long jmp = (long)TV2NUM(pop(stack));
            if(jmp + pc_val >= max || jmp + (long)pc_val < 0) {
                ERROR("Invalid jump: %ld", jmp);
            }
            pc_val += jmp;
            DISPATCH;
        }
        case OP_PUSHCONST: {
            int index = TV2INST(*++pc_val);
            if(index >= (int)block->k->size) {
                ERROR("Constant index out of bounds: %d", index);
            }
            TValue k = getIndex(block->k, index);

            push(stack, k);
            DISPATCH;
        }
        case OP_PUSHVAR: {
            int index = TV2INST(*++pc_val);

            if(index < 0 || index >= block->sizev) {
                ERROR("Variable index out of bounds: %d", index);
            }

            DEBUGF("PUSHVAR, index %d, value >> %s\n", index, TValue_to_string(block->vars[index]));

            TValue var = block->vars[index];
            var.value.var.index = index;

            block->vars[index] = var;

            push(stack, var);
            DISPATCH;
        }
        case OP_SETVAR: {
            EXPECT_ON_STACK(2);
            TValue var = pop(stack);

            if(var.type != TYPE_VAR) {
                ERROR("Expected a var, but got %s", TValue_type_to_string(var));
            }

            int index = var.value.var.index;

            TValue *val = malloc(sizeof(TValue));

            *val = pop(stack);

            block->vars[index] = createVar(val);

            DEBUGF("SETVAR, index %d, value >> %s\n", index, TValue_to_string(block->vars[index]));

            DISPATCH;
        }
        case OP_VALUEVAR: {
            EXPECT_ON_STACK(1);
            TValue var = pop(stack);

            if(var.type != TYPE_VAR) {
                ERROR("Expected a var, but got %s", TValue_type_to_string(var));
            }

            Value val = *var.value.var.value;
            AttoType type = var.value.var.type;

            TValue t;
            t.value = val;
            t.type = type;

            push(stack, t);
            DISPATCH;
        }
        case OP_BOOLVALUE: {
            EXPECT_ON_STACK(1);

            TValue tos = pop(stack);

            int bool = boolValue(tos);

            valueDestroy(&tos);

            push(stack, createBool(bool));
            DISPATCH;
        }
        case OP_CONCAT: {
            EXPECT_ON_STACK(2);
            TValue top = pop(stack);
            TValue sec = pop(stack);

            if(!(top.type == TYPE_STRING && sec.type == TYPE_STRING)) {
                ERROR("Expected two string values, but got %s and %s", TValue_type_to_string(sec),
                      TValue_type_to_string(top));
            }

            char *top_s = TV2STR(top);
            char *sec_s = TV2STR(sec);


            char *str = malloc(strlen(top_s) + strlen(sec_s));

            strcpy(str, sec_s);
            strcat(str, top_s);

            valueDestroy(&top);
            valueDestroy(&sec);

            push(stack, createString(str, strlen(str), 0));
            free(str);
            DISPATCH;
        }
        case OP_PRINT: {
            EXPECT_ON_STACK(1);
            TValue v = pop(stack);
            char *str = TValue_to_string(v);

            printf("%s", str);

            if(v.type == TYPE_NUMBER) free(str);
            valueDestroy(&v);
            DISPATCH;
        }
        case OP_READLINE: {
            char *buf = malloc(BUFSIZ);
            memset(buf, '\0', BUFSIZ);
            if(fgets(buf, BUFSIZ, stdin) ) {
                char *nl = strchr(buf, '\n');
                if(nl) {
                    *nl = '\0';
                }
            }

            unsigned len = strlen(buf) + 1;
            push(stack, createString(buf, len, 0));

            free(buf);
            DISPATCH;
        }
        case OP_DUMPSTACK:
            print_stack(*stack);
            DISPATCH;

        case OP_CLEARSTACK: {
            Stack s = StackNew();
            StackDestroy(&block->stack);
            *stack = s;
            DISPATCH;
        }
        case OP_CALL: {
            EXPECT_ON_STACK(2);
            TValue fcn = pop(stack);
            TValue num = pop(stack);

            // FIXME: this explodes when types aren't right :(
            if(fcn.type != TYPE_FUNCTION || num.type != TYPE_NUMBER) {
                ERROR("Expected function and numeric values, but got %s and %s", TValue_type_to_string(fcn),
                      TValue_type_to_string(num));
            }

            int nargs = (int)TV2NUM(num);

            EXPECT_ON_STACK(nargs);

            int j;
            for(j = 0; j < nargs; ++j) {
                TValue v = pop(stack);
                push(&fcn.value.function.b->stack, v);
            }

            TValue ret = vm_interpret(vm, fcn.value.function.b, 0, nargs);

            if(ret.type != TYPE_NULL) {
                push(stack, ret);
            }

            valueDestroy(&fcn);
            valueDestroy(&num);
            valueDestroy(&fcn);

            DISPATCH;
        }
        case OP_RETURN: {
            EXPECT_ON_STACK(1);

            TValue ret = pop(stack);

            DEBUGF("Finished block, returning with %s\n", TValue_to_string(ret));

            return ret;

            DISPATCH;
        }
        default:
            ERROR("Unrecognized opcode: %d", i);
        }
    }

    DEBUGLN("Finished block");
    return createNull();
}
コード例 #23
0
    PerturbE1(const vd::DynamicsInit& init, const vd::InitEventList& evts)
        : ve::DifferenceEquation::Multiple(init,evts)
    {
	e1 = createVar("e1");
	e0 = createSync("e0");
    }