Esempio n. 1
0
parse_vec_line(char *s,char *lhs,char *rhs,int *type,
	       int *lo,int *hi)
{
  int n=strlen(s);
  int err;
  strupr(s);
  if(msc("INIT ",s)){
    grab_vec_ics(&s[5],lhs,rhs);
    /* printf("vector ic: %s %s \n",lhs,rhs); */
    return VEC_INIT;
  }
  if(msc("ENDVECTOR",s)){
    /*  printf("End vector \n"); */
    return END_VECTOR;
  }
  if(index(s,';')!=NULL){
    /* printf("End vecrhs \n"); */
    return END_VRHS;
  }
  if(msc("NVEC",s)||isdigit(s[0])){
    *type=get_vect_domain(s,lo,hi);
    /* if(*type==1||*type==3)
     printf("lower limit: %d ",*lo);
   if(*type==2||*type==3)
     printf("upper limit: %d ",*hi);
   printf("\n");
    */
    return VEC_DOMAIN;
  }
  err=get_rhs_lhs(s,lhs,rhs,type);
  /* printf(" type %d %s  %s\n",*type,lhs,rhs);   */
  if(err==0)return VEC_RHS;
  return VEC_NOOP;
  
}
Esempio n. 2
0
main()
{
	borland();
	gcc();
	msc();
	sunpro();
	unknown();
	exit(0);
}
/**
 * Checks whether there exists a satisfying example for formula
 *
 * @return: true if there exists a sat example
 */
bool existsSatisfyingExample(Automaton & aut, MacroStateSet* initialState, PrefixListType formulaPrefixSet) {
	unsigned int determinizationNo = formulaPrefixSet.size();
	bool stateIsFinal;

	StateSetList worklist;
	StateSetList processed;
	worklist.push_back(initialState);

	// while we have states to handle
	while(worklist.size() != 0) {
		TStateSet* q = worklist.back();
		worklist.pop_back();
		processed.push_back(q);

		// if some state is final then, there exists a satisfying example
		if(StateIsFinal(aut, q, determinizationNo, formulaPrefixSet)) {
			return true;
		} else {
			// construct the post of the state
			const MacroTransMTBDD & postMTBDD = GetMTBDDForPost(aut, q, determinizationNo, formulaPrefixSet);

			// collect reachable state to one macro state which is the successor of this procedure
			StateSetList reachable;
			MacroStateCollectorFunctor msc(reachable);
			msc(postMTBDD);

			// push all successors to worklist
			for (auto it = reachable.begin(); it != reachable.end(); ++it) {
				if (isNotEnqueued(processed, *it, determinizationNo)) {
					worklist.push_back(*it);
				}
			}
		}
	}

	// didn't find a accepting state, ending
	return false;
}
Esempio n. 4
0
StorageChunk StorageChunk::new_from_buffer(const Vec3i &location,
	const Vector<uint8_t> &contents, Error *err)
{
	if (contents.length() < 4 || slice_cast<const char>(contents.sub(0, 4)) != "NGSC") {
		err->set("Bad magic, NGSC expected");
		return StorageChunk(location);
	}

	ByteReader br(contents.sub(4));
	Vec3i chunk_size, storage_chunk_size;

	chunk_size.x = br.read_int32(err);
	chunk_size.y = br.read_int32(err);
	chunk_size.z = br.read_int32(err);
	if (*err)
		return StorageChunk(location);

	if (chunk_size != CHUNK_SIZE) {
		err->set("Mismatching chunk sizes, file: (%d %d %d), expected: (%d %d %d)",
			VEC3(chunk_size), VEC3(CHUNK_SIZE));
		return StorageChunk(location);
	}

	storage_chunk_size.x = br.read_int32(err);
	storage_chunk_size.y = br.read_int32(err);
	storage_chunk_size.z = br.read_int32(err);
	if (*err)
		return StorageChunk(location);

	if (storage_chunk_size != STORAGE_CHUNK_SIZE) {
		err->set("Mismatching storage chunk sizes, file: (%d %d %d), expected: (%d %d %d)",
			VEC3(storage_chunk_size), VEC3(STORAGE_CHUNK_SIZE));
		return StorageChunk(location);
	}

	auto tmp = br.read_compressed(err);
	if (*err)
		return StorageChunk(location);

	StorageChunk msc(location);
	br = ByteReader(tmp);
	for (int i = 0, n = volume(storage_chunk_size); i < n; i++) {
		Chunk &c = msc.chunks[i];
		c.lods[0].deserialize(&br, CHUNK_SIZE + Vec3i(1), err);
		if (*err)
			return StorageChunk(location);
	}

	return msc;
}
Esempio n. 5
0
void SonarMap::addScan(double sonar_x, double sonar_y, double sonar_theta, double fov, double max_range, double distance, double uncertainty)
{
	int cx=0, cy=0;
	double wx = 0.0, wy = 0.0;

	convertToCell(sonar_x, sonar_y, cx, cy);
	mapstore::MapStoreCone msc(double(cx), double(cy), sonar_theta, fov, distance/resolution_);


	std::list<int> occxs;
	std::list<int> occys;
	std::list<double> occ_vals;
	double sum_occupied = 0;

	if (distance<uncertainty/2) {
		//fixes crashing on wall entering
		return;
	}

	while (msc.nextCell(cx,cy)) {

		if (convertToMap(cx, cy, wx, wy)) {

			double tmp_lin_dist = computeEuclideanDistance(wx, wy, sonar_x, sonar_y);
			double tmp_ang_dist = computeAngularDistance(sonar_theta, atan2(wy-sonar_y, wx-sonar_x));

			double p_linear;
			double p_angular = this->Ea(fov, tmp_ang_dist);

			double tmp_occ = 0;
			double tmp_free = 0;

			if (abs(distance-max_range)<uncertainty) {
				//beams do not hit any obstacle
				p_linear = this->ErFree(distance, tmp_lin_dist, uncertainty);
				tmp_free = p_linear*p_angular;
			} else {
				if (tmp_lin_dist<distance) {
					p_linear = this->ErFree(distance, tmp_lin_dist, uncertainty);
					tmp_free = p_linear*p_angular;
				} else {
					double p_linear = this->ErOcc(distance, tmp_lin_dist, uncertainty);
					tmp_occ = p_linear*p_angular;
				}
			}

			double free_val_prev = map_free_.get(cx,cy);
			double occ_val_prev = map_occupied_.get(cx,cy);

			double free_val_new = free_val_prev + tmp_free - free_val_prev*tmp_free;
			double occ_val_new = tmp_occ*(1-free_val_new);
			sum_occupied += occ_val_new;

			occ_vals.push_front(occ_val_new);
			occxs.push_front(cx);
			occys.push_front(cy);

			map_free_.set(cx,cy, free_val_new);
		}
	}

	//Normalization pass over stored x and y's
	while (!occ_vals.empty()) {
		cx = occxs.back();
		cy = occys.back();
		double tmp_val = occ_vals.back();

		if (sum_occupied>0.05) {
			//normalization not possible otherwise
			double normalized_occ = tmp_val/sum_occupied;
			double occ_prev = map_occupied_.get(cx,cy);
			map_occupied_.set(cx,cy, occ_prev + normalized_occ - occ_prev*normalized_occ);
		}

		double occ = map_occupied_.get(cx,cy);
		double free = map_free_.get(cx,cy);

		if (occ>free) {
			map_.set(cx, cy, occ);
		} else {
			map_.set(cx,cy, -free);
		}

		occxs.pop_back();
		occys.pop_back();
		occ_vals.pop_back();
	}
}
int main(void) {
	cleanup();
	
	printf("test simple instantiation\n");
	{
		MergeSpaceCoordinator msc(LOCK_DIR,3,"unittest_data_dir");
	}
	cleanup();
	
	printf("test simple invariant established by ctor\n");
	{
		MergeSpaceCoordinator msc(LOCK_DIR,3,"unittest_data_dir");
		assert(!msc.acquired());
	}
	cleanup();
	
	printf("test simple acquisition\n");
	{
		MergeSpaceCoordinator msc(LOCK_DIR,3,"unittest_data_dir");
		assert(msc.acquire(17));
		assert(msc.acquired());
		assert(access((std::string(LOCK_DIR)+"/lock0").c_str(),F_OK)==0);
		msc.relinquish();
		struct stat st;
		assert(stat(LOCK_DIR"/lock0", &st)==0);
		assert(st.st_size==0);
	}
	cleanup();
	
	printf("test multiple acquisition\n");
	{
		MergeSpaceCoordinator msc0(LOCK_DIR,3,"unittest_data_dir");
		MergeSpaceCoordinator msc1(LOCK_DIR,3,"unittest_data_dir");
		MergeSpaceCoordinator msc2(LOCK_DIR,3,"unittest_data_dir");
		MergeSpaceCoordinator msc3(LOCK_DIR,3,"unittest_data_dir");
		assert(msc0.acquire(17));
		assert(msc0.acquired());
		assert(access((std::string(LOCK_DIR)+"/lock0").c_str(),F_OK)==0);
		assert(msc1.acquire(17));
		assert(msc1.acquired());
		assert(access((std::string(LOCK_DIR)+"/lock1").c_str(),F_OK)==0);
		assert(msc2.acquire(17));
		assert(msc2.acquired());
		assert(access((std::string(LOCK_DIR)+"/lock2").c_str(),F_OK)==0);
		assert(!msc3.acquire(17));
		assert(access((std::string(LOCK_DIR)+"/lock3").c_str(),F_OK)!=0);
		msc0.relinquish();
		msc1.relinquish();
		msc2.relinquish();
	}
	cleanup();
	
	printf("test junk in lock files\n");
	{
		mkdir(LOCK_DIR,0777);
		FILE *fp=fopen(LOCK_DIR "/lock0", "w");
		fprintf(fp,"banana");
		fclose(fp);
		MergeSpaceCoordinator msc(LOCK_DIR,1,"unittest_data_dir");
		assert(msc.acquire(17));
		fp = fopen(LOCK_DIR "/lock0", "r");
		assert(fp!=NULL);
		char buf[ 20];
		fgets(buf,sizeof(buf),fp);
		fclose(fp);
		assert(strcmp(buf,"banana")!=0);
		assert(strtol(buf,0,0)>0);
		msc.relinquish();
	}
	cleanup();

	printf("test old pid in lock files\n");
	{
		int pid=0;
		while(kill(pid,0)==0)
			pid++;
		mkdir(LOCK_DIR,0777);
		FILE *fp=fopen(LOCK_DIR "/lock0", "w");
		fprintf(fp,"%d",pid);
		fclose(fp);
		MergeSpaceCoordinator msc(LOCK_DIR,1,"unittest_data_dir");
		assert(msc.acquire(17));
	}
	cleanup();

	printf("test existing pid in lock files\n");
	{
		int pid=0;
		while(kill(pid,0)!=0)
			pid++;
		mkdir(LOCK_DIR,0777);
		FILE *fp=fopen(LOCK_DIR "/lock0", "w");
		fprintf(fp,"%d",pid);
		fclose(fp);
		MergeSpaceCoordinator msc(LOCK_DIR,1,"unittest_data_dir");
		assert(!msc.acquire(17));
	}
	cleanup();


	printf("test lock holding. This takes more than a minute to test\n");
	{
		MergeSpaceCoordinator msc0(LOCK_DIR,1,"unittest_data_dir");
		assert(msc0.acquire(17));
		assert(msc0.acquired());
		//lock file must be touched every 30 seconds
		struct stat st0;
		assert(stat(LOCK_DIR "/lock0", &st0)==0);
		sleep(32);
		struct stat st1;
		assert(stat(LOCK_DIR "/lock0", &st1)==0);
		assert(st0.st_mtim.tv_sec < st1.st_mtim.tv_sec);
	}
	cleanup();
}