Ejemplo n.º 1
0
int main()
{
	SimpleDigraph<car_t*>* model = new SimpleDigraph<car_t*>();
	vector<Cell*> road;
	for (unsigned i = 0; i < 10; i++)
	{
		car_t* car = NULL;
		if (i == 0 || i == 5)
		{
			car = new car_t;
			car->ID = i;
			car->spd = MAX_SPEED/2.0;
			if (i == 0) car->spd = MAX_SPEED;
		}
		road.push_back(new Cell(i,car));
		model->add(road[i]);
	}
	for (unsigned i = 0; i < 9; i++)
	{
		model->couple(road[i],road[i+1]);
	}
	ParSimulator<car_t*>* sim = new ParSimulator<car_t*>(model,new CarMessageManager());
	sim->addEventListener(new Listener());
	sim->execUntil(2.0);
	sim->execUntil(100.0);
	delete sim;
	delete model;
	return 0;
}
Ejemplo n.º 2
0
int main()
{
	SimpleDigraph<IO_Type>* model = new SimpleDigraph<IO_Type>();
	SingleBoard_8052 *computer = new SingleBoard_8052("test.ihx");
	MemSetter* mem = new MemSetter();
	model->add(computer);
	model->add(mem);
	model->couple(computer,mem);
	model->couple(mem,computer);
	Simulator<IO_Type>* sim = new Simulator<IO_Type>(model);
	while (sim->nextEventTime() < 10.0)
	{
		sim->execNextEvent();
	}
	delete sim;
	delete computer;
}
Ejemplo n.º 3
0
int main()
{
	// Create the open modelica model
	test2Ext* pendulum = new test2Ext();
	Hybrid<OMC_ADEVS_IO_TYPE>* hybrid_model =
		new Hybrid<OMC_ADEVS_IO_TYPE>(
		pendulum,
		new rk_45<OMC_ADEVS_IO_TYPE>(pendulum,1E-8,0.001),
		new bisection_event_locator<OMC_ADEVS_IO_TYPE>(pendulum,1E-6));
	// Create the test oracle
	oracle* test_oracle = new oracle();
	Hybrid<OMC_ADEVS_IO_TYPE>* hybrid_model_oracle =
		new Hybrid<OMC_ADEVS_IO_TYPE>(
		test_oracle,
		new rk_45<OMC_ADEVS_IO_TYPE>(test_oracle,1E-8,0.001),
		new linear_event_locator<OMC_ADEVS_IO_TYPE>(test_oracle,1E-6));
	// Combine them
	SimpleDigraph<double>* model = new SimpleDigraph<double>();
	model->add(hybrid_model);
	model->add(hybrid_model_oracle);
	model->couple(hybrid_model,hybrid_model_oracle);
	model->couple(hybrid_model_oracle,hybrid_model);
	// Create the simulator
	Simulator<OMC_ADEVS_IO_TYPE>* sim =
		new Simulator<OMC_ADEVS_IO_TYPE>(model);
	assert(fabs(pendulum->get_theta()) < 1E-6);
	cout << "# time, x, y" << endl;
	while (sim->nextEventTime() <= 25.0)
	{
		cout << sim->nextEventTime() << " ";
		sim->execNextEvent();
		cout << pendulum->get_x() << " "  
		<< pendulum->get_y() << " "
		<< pendulum->get_theta() << " " 
		<< hybrid_model_oracle->getState(0) << endl;
	}
	assert(test_oracle->getTestCount() > 0);
	delete sim;
	delete model;
	return 0;
}