コード例 #1
0
ファイル: ipar.cpp プロジェクト: GAIA-GMU/PAR
int 
Actionary::setCondition(MetaAction* act, int which)
{
	char buf[MAXBUF], className[64];
	char locbuf[MAXBUF];
	int res;

	if (act == NULL) 
		return -1;

	std::string str;
	switch(which) {
		case 0:
			str = this->getApplicabilityCond(act);
			break;
		case 1:
			str = this->getCulminationCond(act);
			break;
		case 2:
			str = this->getPreparatorySpec(act);
			break;
		case 3:
			str = this->getExecutionSteps(act);
			break;
		default:
			par_debug("Error in Actionary::setCondition\n");
	}

	
	if (!strcmp(str.c_str(),"no") || !strcmp(str.c_str()," ") ||!strcmp(str.c_str(),""))
		return -1;
	strcpy_s(locbuf,512,actionLocation);
	strcat_s(locbuf,512,str.c_str());
	par_debug("In Actionary::setCondition for class %d, str = %s\n",act->getID(),str.c_str());
	res = runPySimple(locbuf, true); // str is the filename
	if (res < 0) {
		//par_debug("%s has a negitive res\n", locbuf);
		return res;
	 }

	//par_debug("In setCondition for action %s with id %d\n",act->getActionName(),act->getID());
	sprintf_s(className, 64, "Class%d", act->getID());
	sprintf_s(buf, 128, "%s.%s = %s\n", className,
		   conditionNames[which], conditionNames[which]);
	//par_debug("Condition is %s\n", buf);
	int result = PyRun_SimpleString(buf);
	return result;
}
コード例 #2
0
ファイル: par.c プロジェクト: awasiljew/athena-cuda
int main(int argc, char *argv[])
{
  if (argc == 1) {
    printf("Usage: %s par-file [block-name par-name]\n",argv[0]);
    exit(0);
  }

  par_debug(0);
  par_open(argv[1]);
  par_cmdline(argc,argv);
  if (argc == 4) {
    char *cp = par_gets(argv[2],argv[3]);
    int ival;
    double dval;
    char *sval = "hello world";
    printf("PAR_GETS: %s.%s = \"%s\"\n",argv[2],argv[3],cp);
    printf("PAR_GETI: %s.%s = \"%d\" as integer\n",
      argv[2],argv[3],par_geti(argv[2],argv[3]));
    printf("PAR_GETD: %s.%s = \"%g\" as double\n",
      argv[2],argv[3],par_getd(argv[2],argv[3]));
    free(cp);
  }
  par_dump(0,stdout);
  par_close();
  return 0;
}
コード例 #3
0
ファイル: agentnet.cpp プロジェクト: GAIA-GMU/PAR
bool	
AgentNet::readyToGo(iPAR* cfipar)
{
	// is this the timing such that this ipar is ready to be executed?
	double tempTime = cfipar->getStartTime(); 

	if (tempTime <= partime->getCurrentTime()){
		return true;
	}

	// if there is an object parameter, get the distance from the current agent location to this 
	// object.  If the action isn't locomoting, then the agent will likely have to locomote to the object
	// We will pop the action sooner to try to allow for the time it will take.  
	// We will always assume that the first object is the salient object.
	if (cfipar->par->getNumObjects() > 0)
	{
		MetaObject* blah = cfipar->getObject(0);
		if (blah != NULL)
		{
			MetaObject *obj = cfipar->getObject(0);
			assert(obj);
			par_debug("In AgentNet::readyToGo, object is %s\n",obj->getObjectName().c_str());
			
			
			//Vector<3> *objPos = obj->getPosition();
			std::string agentName = cfipar->getAgent()->getObjectName();
			//MetaObject *agent = actionary->searchByNameObj(agentName);
			//assert(agent);
			/*Vector<3> *agtPos = agent->getPosition();
			float dist;
				
			dist = (objPos->v[0] - agtPos->v[0]) * (objPos->v[0] - agtPos->v[0]);
			dist = dist + (objPos->v[1] - agtPos->v[1]) * (objPos->v[1] - agtPos->v[1]);
			dist = dist + (objPos->v[2] - agtPos->v[2]) * (objPos->v[2] - agtPos->v[2]);
			dist = sqrt(dist);*/

			double adjustedTime = tempTime - getTimeToObject(cfipar->getAgent(), obj);
				//(dist * 0.6897 * 10);  // assuming walking speed of 1.45m/s
			par_debug("Adjusted time is %f\n", adjustedTime);
			if (adjustedTime <= partime->getCurrentTime())
				return true;
		}
	}
	
	return false;
}
コード例 #4
0
ファイル: par.c プロジェクト: awasiljew/athena-cuda
int main(int argc, char *argv[])
{
  int mytid;
/* int numprocs; */
  int  namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME];

  par_debug(0);

  if(MPI_SUCCESS != MPI_Init(&argc,&argv))
    ath_error("Error on calling MPI_Init\n");
/* Get the number of processes */
/* MPI_Comm_size(MPI_COMM_WORLD,&numprocs); */
/* Get my task id, or rank as it is called in MPI */
  MPI_Comm_rank(MPI_COMM_WORLD,&mytid);
/* Get the name of the processor or machine name */
  MPI_Get_processor_name(processor_name,&namelen);

  printf("My task id / rank = %d on %s\n",mytid, processor_name);

/* Parent and child have different jobs */
  if(mytid != 0)
    printf("My Parent's task id / rank = 0\n");
  else{
    printf("I am the Parent\n");

    if (argc == 1) {
      printf("Usage: %s par-file [block-name par-name]\n",argv[0]);
      exit(0);
    }

    par_open(argv[1]);
    par_cmdline(argc,argv);
    if (argc == 4) {
      char *cp = par_gets(argv[2],argv[3]);
      printf("PAR_GETS: %s.%s = \"%s\"\n",argv[2],argv[3],cp);
      printf("PAR_GETI: %s.%s = \"%d\" as integer\n",
        argv[2],argv[3],par_geti(argv[2],argv[3]));
      printf("PAR_GETD: %s.%s = \"%g\" as double\n",
        argv[2],argv[3],par_getd(argv[2],argv[3]));
      free(cp);
    }
  }
 
  par_dist_mpi(mytid,MPI_COMM_WORLD);
  par_dump(0,stdout);
  par_close();

  MPI_Finalize();

  return 0;
}
コード例 #5
0
ファイル: agentnet.cpp プロジェクト: GAIA-GMU/PAR
iPAR* 
AgentNet::getFirstAction(void)
{
  // return the action on the queue that has the least startTime
  int i;
  // check in the queue
  iPAR *cfipar = NULL; // current first ipar on the queue
  iPAR *pfipar = NULL; // ipar that's start time has passed with the highest priority
  double tempTime;
  double currentTime = partime->getCurrentTime();
  int priority = 0;

  par_debug("QueueMgr: there are %d items on the  iparQ\n",iparQ->size());
  // Find the ipar with the smallest startTime
  std::list<iPAR*>::iterator iter;
  for(iter=iparQ->begin(),i=0; iter!=iparQ->end(); iter++,i++)
  {
	  if (i == 0)
	  {
			cfipar = *iter;
			tempTime = (*iter)->getStartTime();
	  }
	  else
	  {
		  if ((*iter)->getStartTime() < tempTime)
		  {
			  cfipar = *iter;
			  tempTime = (*iter)->getStartTime();
		  }
	  }

	  if ((*iter)->getStartTime() <= currentTime && 
		  (*iter)->getPriority() > priority)
	  {
		  priority = (*iter)->getPriority();
		  pfipar = *iter;
	  }
		

  }

  // decide between cfipar and pfipar
  if (pfipar == NULL)
	return cfipar;

  if (priority > cfipar->getPriority())
	  return pfipar;

  return cfipar;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: GAIA-GMU/PAR
int main(void){
	partime = new parTime();			// setup the timing info for the simulation
	partime->setTimeOffset(8,30,30);	// hours, minutes, seconds from midnight
	partime->setTimeRate(1);			// how fast should time change
	setUpActionTable();					// Builds the action table
	// Builds a new agent and gives him HumanAction capabilities
	AgentProc* agent=new AgentProc("Agent_0");
	agent->setCapability("HumanAction");
	Vector<3>* vec= new Vector<3>();
	vec->v[0]=0.0f;
	vec->v[1]=0.0f;
	vec->v[2]=0.0f;
	agent->getObject()->setPosition(vec);

	//Builds two new Objects (an oven and food)
	MetaObject* ob1=new MetaObject("Food_0",false);
	vec->v[0]=-3;
	ob1->setPosition(vec);
	MetaObject* ob2=new MetaObject("Oven_0",false);
	vec->v[0]=3;
	vec->v[1]=3;
	vec->v[2]=3;
	ob2->setPosition(vec);

	// Creates an IPAR
	char* objects[]= {strdup(ob1->getObjectName().c_str()),strdup(ob2->getObjectName().c_str())};
	//Cook is used here as it uses a complex action as a primitive
	//to show that a complex action can be used as a primitive
	try{
		iPAR* iparTest = new iPAR("Cook",agent->getName(),objects);
		iparTest->setFinished(false);
		iparTest->setDuration(10);// This should run for 10 seconds
		iparTest->setStartTime(partime->getCurrentTime());
		iparTest->setPriority(1);
		int error=0;
		agent->addAction(iparTest);
		for(int i=0; i<100000; i++){
			LWNetList::advance(&error);      
		}
	}
	catch(iPARException &e){
		par_debug("%s\n",e.printMsg());
	}

	system("PAUSE");
	return 0;
}
コード例 #7
0
ファイル: agentnet.cpp プロジェクト: GAIA-GMU/PAR
void
AgentNet::actfunc_popaction(void)
{
  iPAR *cfipar = NULL; // current first ipar on the queue
 
  cfipar = this->getFirstAction();
  if (cfipar == NULL)
	  return;

  if (this->readyToGo(cfipar)) // is the timing right?
  {
	ipar = cfipar;
	ipar->copyValuesToPython();//At this point, the action is a go, and so we assign values from it into python
	iparQ->remove(cfipar);
	par_debug("QueueMgr: now popped action %s from the queue\n",ipar->par->getActionName().c_str());
	markfinished();
  }
}