Exemplo n.º 1
0
int main(int argc, char* argv[])
{
    // Virtual Worldの作成
    WorldPtr world = createWorld();
    RobotPtr robot = createRobot(world);

    // Agentの作成
    ActionPtr        action = createAction(robot);
    DistSensorPtr    sensor = createDistSensor(robot);
    EnvironmentPtr   env    = createEnvironment(sensor);
    ThreadedAgentPtr agent  = createAgent(sensor, action);

    // 初期化
    env->init();
    agent->init();
    robot->init();

    QApplication app(argc, argv);
    MainWindow window;
    window.setWorldModel(world);
    window.setRobotModel(robot);
    window.setEnvironment(env);
    window.setAgent(agent);

    window.show();
    return app.exec();
}
Exemplo n.º 2
0
StateRef<Agent> AgentGenerator::createAgent(GameState &state, StateRef<Organisation> org,
                                            AgentType::Role role) const
{
	std::list<sp<AgentType>> types;
	for (auto &t : state.agent_types)
		if (t.second->role == role && t.second->playable)
			types.insert(types.begin(), t.second);
	auto type = listRandomiser(state.rng, types);

	return createAgent(state, org, {&state, AgentType::getId(state, type)});
}
Exemplo n.º 3
0
int main (int argc, char** argv) {
  uthread_init (7);
  struct Agent*  a = createAgent();
  // TODO
  uthread_join (uthread_create (agent, a), 0);
  assert (signal_count [MATCH]   == smoke_count [MATCH]);
  assert (signal_count [PAPER]   == smoke_count [PAPER]);
  assert (signal_count [TOBACCO] == smoke_count [TOBACCO]);
  assert (smoke_count [MATCH] + smoke_count [PAPER] + smoke_count [TOBACCO] == NUM_ITERATIONS);
  printf ("Smoke counts: %d matches, %d paper, %d tobacco\n",
          smoke_count [MATCH], smoke_count [PAPER], smoke_count [TOBACCO]);
}
Exemplo n.º 4
0
Pendulum::Pendulum(SimulationEngine& engine, const opal::Matrix44r& transform)
: LearningEntity(10),
mMaxAngle(180),
mMaxVel(500),
mMaxTorque(2)
{
	createAgent();
	opal::Simulator* sim = engine.getSimulator();

	// Create the pendulum Solid.  We use radius, length, and density 
	// values that produce a pendulum mass of ~1.
	mLength = 1;
	mRadius = (opal::real)0.05;
	mPendulumSolid = sim->createSolid();
	mPendulumSolid->setSleepiness(0);

	// Make the pendulum "point" away from the joint anchor.
	opal::Matrix44r pendulumTransform = transform;
	pendulumTransform.rotate(-90, 1, 0, 0);
	mPendulumSolid->setTransform(pendulumTransform);
	opal::CapsuleShapeData capsule;
	capsule.length = mLength;
	capsule.radius = mRadius;
	capsule.material.density = 127;
	mPendulumSolid->addShape(capsule);
	engine.createPhysicalEntity("pole", "Plastic/Green", mPendulumSolid);

	//// TESTING
	//mPendulumSolid->setLinearDamping(0.1);

	// Setup the Joint that connects the pendulum to the static 
	// environment.
	mHinge = sim->createJoint();
	opal::JointAxis axis;
	axis.direction.set(0, 0, 1);
	axis.limitsEnabled = false;
	opal::JointData jointData;
	jointData.setType(opal::HINGE_JOINT);
	jointData.contactsEnabled = false;
	jointData.solid0 = mPendulumSolid;
	jointData.solid1 = NULL;
	opal::Point3r anchor = transform.getPosition();
	anchor[1] += (opal::real)0.5 * mLength;
	jointData.anchor = anchor;
	jointData.axis[0] = axis;
	mHinge->init(jointData);

	// Save the initial Solid configurations for resetting.
	mInitSolidData = mPendulumSolid->getData();
}
Exemplo n.º 5
0
    // whether the VASTATE node has been successfully created
    bool 
    VASTATE::isLogined ()
    {
        // do not login if references to logics do not exist 
        // (that is, createNode () must be called first)
        if (_arb_logics.size () == 0 && _agent_logics.size () == 0)
            return false;
        else if (_state == JOINED)
            return true;

        // create arbitrator & agent
        if (_state == ABSENT)
        {
            // create arbitrator first (to handle incoming LOGIN request from agents)
            // but only if there are valid arbitrator logic specified
            if (_arbitrators.size () < _arb_logics.size ())
                createArbitrator (_arb_logics[0]);
        
            // we create agent AFTER arbitrator is created first
            else if (_agents.size () < _agent_logics.size ())                
            {                       
                Agent *agent = createAgent (_agent_logics[0]);
        
                if (agent != NULL)
                {   
                    // update my peer ID    
                    // TODO: make sure agent logic does it ?
                    //g_self->setSelf (g_agent->getSelf ());
        
                    agent->login (NULL, _pass.c_str (), _pass.length ());
                }
            }
        
            // if both arbitrator & agent are created successfully, move to next stage (wait for join success)
            // NOTE: arbitrator may not be created if public IP is not available at this host
            if (_arbitrators.size () == _arb_logics.size () &&
                _agents.size () == _agent_logics.size ())
                _state = JOINING;
        }

        // check if arbitrator has properly joined the network
        else if (_state == JOINING)
        {
            // see if arbitrator join location is specified
            // NOTE: Position is initialized at the origin (x = 0, y = 0), 
            bool init_pos = !(_arb_position.x == 0 && _arb_position.y == 0);
        
            // if no arbitrator logic or initial position specified, ignore arbitrator join
            // otherwise, check if arbitrator join is already completed
            if (_arb_logics.size () == 0 || 
                init_pos == false || 
                _arbitrators[0]->isJoined ())
                _state = JOINING_2;
            else                 
                _arbitrators[0]->join (_arb_position);
        }
        // check if agent has properly joined the network
        else if (_state == JOINING_2)
        {
            // if no agent logic specified or if join is already completed, 
            // then join is considered done
            if (_agent_logics.size () == 0 ||
                _agents[0]->isJoined ())
                _state = JOINED;
        
            else if (_agents[0]->isAdmitted ())
            {
                // attempt to join
                // NOTE: only the first call to join () after admitted is valid, 
                // so it can be called repetitively
                _agents[0]->setAOI (_agent_aoi.radius);    
                _agents[0]->join (_agent_aoi.center);
            }                                            
        }

        return (_state == JOINED);
    }
Exemplo n.º 6
0
void FeatureExtractor::addFeatureAgent(const std::string &key, const std::string &name) {
  FeatureAgent featureAgent;
  featureAgent.name = key;
  featureAgent.agent = createAgent(0,dims,name,0,0,Json::Value(),Json::Value()); // the rng, trialNum, and predatorInd don't matter here
  featureAgents.push_back(featureAgent);
}