示例#1
0
void LinksAspect::InitializeAspect()
{
	// Evaluation buffers
	_lastPrecSize = -1;
	fifov = NULL;

	// Load parameters
	_seed = GetConfigLong("Seed"); Seed = &_seed;
	Friend_Probability = GetConfigFloat("Friend_Probability");
	Alfa = GetConfigFloat("Alfa");
	Homophilia = GetConfigFloat("Homophilia");
	Heterophilia = GetConfigFloat("Heterophilia");
	Random_Probability = GetConfigFloat("Random_Probability");
	Delete_Probability = GetConfigFloat("Delete_Probability");

	// Get aspects
	_distanceAspect = (DistanceAspect *) this->GetAspect(typeid(DistanceAspect).name());
	// Optional...
	_educationLevelAspect = (EducationLevelAspect *) this->TryGetAspect(typeid(EducationLevelAspect).name());
	_socialCircleAspect = (SocialCircleAspect *) this->TryGetAspect(typeid(SocialCircleAspect).name());

	// Initialize the link elements...
	Members = this->begin->GetSize();
	int qqq=0;
	LinksInfo *element;
	for (Population::Iterator agentId = this->begin;
		agentId != this->end; ++agentId)
	{
		qqq++;
		 element = (*this)[*agentId];
		 element->Degree = 0;
		 element->Predecesors = NULL;
		 list_init(&element->Table);
	}
}
示例#2
0
float ConfigTool::GetConfigFloat(const char* config_key, const char *prefix)
{
	float value=0;

	CombinedKey(config_key, prefix);

	if(the_map.count(cfg_key)>0)
	{
		const char *val=the_map[cfg_key].c_str();
		if(IfNumChar(val[0])) value=(float)atof(the_map[cfg_key].c_str());
		else value=GetConfigFloat(val); //else we search other gobal key without current prefix
	}
	else
	{
		printf("Config key \"%s\" missing!\n", cfg_key);
		exit(-1);
	}

	return value;
}
示例#3
0
int main( int argc, char** argv )
{
    InitTests(argc, argv);

    Describe("Config module")
        .use(dummyExceptionSandbox)

        .it("can be initialized empty.", [](){

            Require(InitConfig(0, NULL) == true);
            DestroyConfig();
        })

        .it("has a proper destructor.", [](){

            const char* argv[] = {"", "--aaa=bbb"};

            {
                Require(InitConfig(2, argv) == true);
                ConfigScope scope;
                Require(strcmp(GetConfigString("aaa",""), "bbb") == 0);
            }

            {
                Require(InitConfig(0, NULL) == true);
                ConfigScope scope;
                Require(GetConfigString("aaa",NULL) == NULL);
            }
        })

        .it("can parse arguments.", [](){

            const char* argv[] = {"", "--aaa=bbb", "--foo=bar", "--ccc=ddd"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(strcmp(GetConfigString("foo",""), "bar") == 0);
            Require(strcmp(GetConfigString("foo","yyy"), "bar") == 0);
            Require(strcmp(GetConfigString("foo",NULL), "bar") == 0);
            Require(strcmp(GetConfigString("xxx",""), "") == 0);
            Require(strcmp(GetConfigString("xxx","yyy"), "yyy") == 0);
            Require(GetConfigString("xxx",NULL) == NULL);
        })

        .it("can convert integer values.", [](){

            const char* argv[] = {"", "--aaa=42", "--bbb=1.1", "--ccc=1.9"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(GetConfigInt("aaa", 0) == 42);
            Require(GetConfigInt("bbb", 0) == 1);
            Require(GetConfigInt("ccc", 0) == 1);
            Require(GetConfigInt("xxx", 0) == 0);
        })

        .it("can convert floating point values.", [](){

            const char* argv[] = {"", "--aaa=42", "--bbb=1.1", "--ccc=1.9"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(GetConfigFloat("aaa", 0) == 42);
            Require(GetConfigFloat("bbb", 0) == 1.1f);
            Require(GetConfigFloat("ccc", 0) == 1.9f);
            Require(GetConfigFloat("xxx", 0.1f) == 0.1f);
        })

        .it("can convert boolean values.", [](){

            const char* argv[] = {
                "",
                "--aaa=42",
                "--bbb=1.1",
                "--ccc=1.9",
                "--ddd=0",
                "--eee=0.0",
                "--fff=true",
                "--ggg=false",
                "--hhh=yes",
                "--jjj=no"};

            Require(InitConfig(10, argv) == true);
            ConfigScope scope;

            Require(GetConfigBool("aaa", false) == true);
            Require(GetConfigBool("bbb", false) == true);
            Require(GetConfigBool("ccc", false) == true);
            Require(GetConfigBool("ddd", true) == false);
            Require(GetConfigBool("eee", true) == false);
            Require(GetConfigBool("fff", false) == true);
            Require(GetConfigBool("ggg", true) == false);
            Require(GetConfigBool("hhh", false) == true);
            Require(GetConfigBool("jjj", true) == false);

            Require(GetConfigBool("xxx", true) == true);
            Require(GetConfigBool("xxx", false) == false);
        })

        .it("can parse ini files.", [](){

            const char* argv[] = {"", "--config=config/Test.ini"};

            Require(InitConfig(2, argv) == true);
            ConfigScope scope;

            Require(GetConfigString("config", NULL) == NULL);
            Require(strcmp(GetConfigString("aaa", ""), "bbb") == 0);
            Require(strcmp(GetConfigString("foo.bar", ""), "baz") == 0);
            Require(strcmp(GetConfigString("foo.hello", ""), "Hello World") == 0);
        });

    return RunTests();
}