예제 #1
0
파일: exec.c 프로젝트: k0gaMSX/uemacs
/*
 * dobuf:
 *	execute the contents of the buffer pointed to
 *	by the passed BP
 *
 *	Directives start with a "!" and include:
 *
 *	!endm		End a macro
 *	!if (cond)	conditional execution
 *	!else
 *	!endif
 *	!return		Return (terminating current macro)
 *	!goto <label>	Jump to a label in the current macro
 *	!force		Force macro to continue...even if command fails
 *	!while (cond)	Execute a loop if the condition is true
 *	!endwhile
 *
 *	Line Labels begin with a "*" as the first nonblank char, like:
 *
 *	*LBL01
 *
 * struct buffer *bp;		buffer to execute
 */
int dobuf(struct buffer *bp)
{
	int status;	/* status return */
	struct line *lp;	/* pointer to line to execute */
	struct line *hlp;	/* pointer to line header */
	struct line *glp;	/* line to goto */
	struct line *mp;		/* Macro line storage temp */
	int dirnum;		/* directive index */
	int linlen;		/* length of line to execute */
	int i;			/* index */
	int c;			/* temp character */
	int force;		/* force TRUE result? */
	struct window *wp;		/* ptr to windows to scan */
	struct while_block *whlist;	/* ptr to !WHILE list */
	struct while_block *scanner;	/* ptr during scan */
	struct while_block *whtemp;	/* temporary ptr to a struct while_block */
	char *einit;		/* initial value of eline */
	char *eline;		/* text of line to execute */
	char *tkn;	/* buffer to evaluate an expresion in */

#if	DEBUGM
	char *sp;		/* temp for building debug string */
	char *ep;	/* ptr to end of outline */
#endif

        tkn = alloca(NSTRING * sizeof(char));
	/* clear IF level flags/while ptr */
	execlevel = 0;
	whlist = NULL;
	scanner = NULL;

	/* scan the buffer to execute, building WHILE header blocks */
	hlp = bp->b_linep;
	lp = hlp->l_fp;
	while (lp != hlp) {
		/* scan the current line */
		eline = lp->l_text;
		i = lp->l_used;

		/* trim leading whitespace */
		while (i-- > 0 && (*eline == ' ' || *eline == '\t'))
			++eline;

		/* if theres nothing here, don't bother */
		if (i <= 0)
			goto nxtscan;

		/* if is a while directive, make a block... */
		if (eline[0] == '!' && eline[1] == 'w' && eline[2] == 'h') {
			whtemp = (struct while_block *)malloc(sizeof(struct while_block));
			if (whtemp == NULL) {
			      noram:mlwrite
				    ("%%Out of memory during while scan");
			      failexit:freewhile
				    (scanner);
				freewhile(whlist);
				return FALSE;
			}
			whtemp->w_begin = lp;
			whtemp->w_type = BTWHILE;
			whtemp->w_next = scanner;
			scanner = whtemp;
		}

		/* if is a BREAK directive, make a block... */
		if (eline[0] == '!' && eline[1] == 'b' && eline[2] == 'r') {
			if (scanner == NULL) {
				mlwrite
				    ("%%!BREAK outside of any !WHILE loop");
				goto failexit;
			}
			whtemp = (struct while_block *)malloc(sizeof(struct while_block));
			if (whtemp == NULL)
				goto noram;
			whtemp->w_begin = lp;
			whtemp->w_type = BTBREAK;
			whtemp->w_next = scanner;
			scanner = whtemp;
		}

		/* if it is an endwhile directive, record the spot... */
		if (eline[0] == '!' && strncmp(&eline[1], "endw", 4) == 0) {
			if (scanner == NULL) {
				mlwrite
				    ("%%!ENDWHILE with no preceding !WHILE in '%s'",
				     bp->b_bname);
				goto failexit;
			}
			/* move top records from the scanner list to the
			   whlist until we have moved all BREAK records
			   and one WHILE record */
			do {
				scanner->w_end = lp;
				whtemp = whlist;
				whlist = scanner;
				scanner = scanner->w_next;
				whlist->w_next = whtemp;
			} while (whlist->w_type == BTBREAK);
		}

	      nxtscan:		/* on to the next line */
		lp = lp->l_fp;
	}

	/* while and endwhile should match! */
	if (scanner != NULL) {
		mlwrite("%%!WHILE with no matching !ENDWHILE in '%s'",
			bp->b_bname);
		goto failexit;
	}

	/* let the first command inherit the flags from the last one.. */
	thisflag = lastflag;

	/* starting at the beginning of the buffer */
	hlp = bp->b_linep;
	lp = hlp->l_fp;
	while (lp != hlp) {
		/* allocate eline and copy macro line to it */
		linlen = lp->l_used;
		if ((einit = eline = malloc(linlen + 1)) == NULL) {
			mlwrite("%%Out of Memory during macro execution");
			freewhile(whlist);
			return FALSE;
		}
		strncpy(eline, lp->l_text, linlen);
		eline[linlen] = 0;	/* make sure it ends */

		/* trim leading whitespace */
		while (*eline == ' ' || *eline == '\t')
			++eline;

		/* dump comments and blank lines */
		if (*eline == ';' || *eline == 0)
			goto onward;

#if	DEBUGM
		/* if $debug == TRUE, every line to execute
		   gets echoed and a key needs to be pressed to continue
		   ^G will abort the command */

		if (macbug) {
			strcpy(outline, "<<<");

			/* debug macro name */
			strcat(outline, bp->b_bname);
			strcat(outline, ":");

			/* debug if levels */
			strcat(outline, itoa(execlevel));
			strcat(outline, ":");

			/* and lastly the line */
			strcat(outline, eline);
			strcat(outline, ">>>");

			/* change all '%' to ':' so mlwrite won't expect arguments */
			sp = outline;
			while (*sp)
				if (*sp++ == '%') {
					/* advance to the end */
					ep = --sp;
					while (*ep++);
					/* null terminate the string one out */
					*(ep + 1) = 0;
					/* copy backwards */
					while (ep-- > sp)
						*(ep + 1) = *ep;

					/* and advance sp past the new % */
					sp += 2;
				}

			/* write out the debug line */
			mlforce(outline);
			update(TRUE);

			/* and get the keystroke */
			if ((c = get1key()) == abortc) {
				mlforce("(Macro aborted)");
				freewhile(whlist);
				return FALSE;
			}

			if (c == metac)
				macbug = FALSE;
		}
#endif

		/* Parse directives here.... */
		dirnum = -1;
		if (*eline == '!') {
			/* Find out which directive this is */
			++eline;
			for (dirnum = 0; dirnum < NUMDIRS; dirnum++)
				if (strncmp(eline, dname[dirnum],
					    strlen(dname[dirnum])) == 0)
					break;

			/* and bitch if it's illegal */
			if (dirnum == NUMDIRS) {
				mlwrite("%%Unknown Directive");
				freewhile(whlist);
				return FALSE;
			}

			/* service only the !ENDM macro here */
			if (dirnum == DENDM) {
				mstore = FALSE;
				bstore = NULL;
				goto onward;
			}

			/* restore the original eline.... */
			--eline;
		}

		/* if macro store is on, just salt this away */
		if (mstore) {
			/* allocate the space for the line */
			linlen = strlen(eline);
			if ((mp = lalloc(linlen)) == NULL) {
				mlwrite
				    ("Out of memory while storing macro");
				return FALSE;
			}

			/* copy the text into the new line */
			for (i = 0; i < linlen; ++i)
				lputc(mp, i, eline[i]);

			/* attach the line to the end of the buffer */
			bstore->b_linep->l_bp->l_fp = mp;
			mp->l_bp = bstore->b_linep->l_bp;
			bstore->b_linep->l_bp = mp;
			mp->l_fp = bstore->b_linep;
			goto onward;
		}


		force = FALSE;

		/* dump comments */
		if (*eline == '*')
			goto onward;

		/* now, execute directives */
		if (dirnum != -1) {
			/* skip past the directive */
			while (*eline && *eline != ' ' && *eline != '\t')
				++eline;
			execstr = eline;

			switch (dirnum) {
			case DIF:	/* IF directive */
				/* grab the value of the logical exp */
				if (execlevel == 0) {
					if (macarg(tkn) != TRUE)
						goto eexec;
					if (stol(tkn) == FALSE)
						++execlevel;
				} else
					++execlevel;
				goto onward;

			case DWHILE:	/* WHILE directive */
				/* grab the value of the logical exp */
				if (execlevel == 0) {
					if (macarg(tkn) != TRUE)
						goto eexec;
					if (stol(tkn) == TRUE)
						goto onward;
				}
				/* drop down and act just like !BREAK */

			case DBREAK:	/* BREAK directive */
				if (dirnum == DBREAK && execlevel)
					goto onward;

				/* jump down to the endwhile */
				/* find the right while loop */
				whtemp = whlist;
				while (whtemp) {
					if (whtemp->w_begin == lp)
						break;
					whtemp = whtemp->w_next;
				}

				if (whtemp == NULL) {
					mlwrite
					    ("%%Internal While loop error");
					freewhile(whlist);
					return FALSE;
				}

				/* reset the line pointer back.. */
				lp = whtemp->w_end;
				goto onward;

			case DELSE:	/* ELSE directive */
				if (execlevel == 1)
					--execlevel;
				else if (execlevel == 0)
					++execlevel;
				goto onward;

			case DENDIF:	/* ENDIF directive */
				if (execlevel)
					--execlevel;
				goto onward;

			case DGOTO:	/* GOTO directive */
				/* .....only if we are currently executing */
				if (execlevel == 0) {

					/* grab label to jump to */
					eline =
					    token(eline, golabel, NPAT);
					linlen = strlen(golabel);
					glp = hlp->l_fp;
					while (glp != hlp) {
						if (*glp->l_text == '*' &&
						    (strncmp
						     (&glp->l_text[1],
						      golabel,
						      linlen) == 0)) {
							lp = glp;
							goto onward;
						}
						glp = glp->l_fp;
					}
					mlwrite("%%No such label");
					freewhile(whlist);
					return FALSE;
				}
				goto onward;

			case DRETURN:	/* RETURN directive */
				if (execlevel == 0)
					goto eexec;
				goto onward;

			case DENDWHILE:	/* ENDWHILE directive */
				if (execlevel) {
					--execlevel;
					goto onward;
				} else {
					/* find the right while loop */
					whtemp = whlist;
					while (whtemp) {
						if (whtemp->w_type ==
						    BTWHILE
						    && whtemp->w_end == lp)
							break;
						whtemp = whtemp->w_next;
					}

					if (whtemp == NULL) {
						mlwrite
						    ("%%Internal While loop error");
						freewhile(whlist);
						return FALSE;
					}

					/* reset the line pointer back.. */
					lp = whtemp->w_begin->l_bp;
					goto onward;
				}

			case DFORCE:	/* FORCE directive */
				force = TRUE;

			}
		}

		/* execute the statement */
		status = docmd(eline);
		if (force)	/* force the status */
			status = TRUE;

		/* check for a command error */
		if (status != TRUE) {
			/* look if buffer is showing */
			wp = wheadp;
			while (wp != NULL) {
				if (wp->w_bufp == bp) {
					/* and point it */
					wp->w_dotp = lp;
					wp->w_doto = 0;
					wp->w_flag |= WFHARD;
				}
				wp = wp->w_wndp;
			}
			/* in any case set the buffer . */
			bp->b_dotp = lp;
			bp->b_doto = 0;
			free(einit);
			execlevel = 0;
			freewhile(whlist);
			return status;
		}

	      onward:		/* on to the next line */
		free(einit);
		lp = lp->l_fp;
	}

      eexec:			/* exit the current function */
	execlevel = 0;
	freewhile(whlist);
	return TRUE;
}
int main(int argc, char* argv[]) {

	int BoxX { }, BoxY { }, BoxZ { }, TypeA { }, TypeB { }, Arms { };
	long int Steps_Start { }, Steps_Total { }, Steps_Output { };
	double Temperature { }, Lambda { }, Shear { }, StepSize { };
	bool MPC_on {false};
	string s_para { };
	stringstream ss_para { }, ss_para_new { };
	Thermostat *thermostat{};
	Hydrodynamics *hydrodynamics{};

	s_para = std::string(argv[1]);
	if (!file_exists(s_para)) {
		std::cout << "input file does not exist";
		return 1;
	}


	std::string find_this = "end_config";
	std::string::size_type i = s_para.find(find_this);
	std::cout << i << std::endl;
	if (i != std::string::npos){
		s_para.erase(i, find_this.length());
		s_para.erase(0, i);
	}
	find_this = "./results/";
	i = s_para.find(find_this);
	if (i != std::string::npos){
		s_para.erase(i, find_this.length());
	}

	find_this = ".pdb";
	i = s_para.find(find_this);
	if (i != std::string::npos) s_para.erase(i, find_this.length());
	ss_para << s_para;

	std::cout << s_para << std::endl;
	std::cout << find_parameter(s_para, "Shear") << std::endl;
	BoxX = stoi(find_parameter(s_para,"Lx"));
	BoxY = stoi(find_parameter(s_para,"Ly"));
	BoxZ = stoi(find_parameter(s_para,"Lz"));
	TypeA = stoi(find_parameter(s_para,"A"));
	TypeB = stoi(find_parameter(s_para,"B"));
	Arms = stoi(find_parameter(s_para,"Arms"));
	Steps_Start = stol(find_parameter(s_para,"run"));
	Temperature = stod(find_parameter(s_para,"T"));
	Shear = stod(find_parameter(s_para, "Shear"));
	Lambda = stod(find_parameter(s_para,"Lambda"));

	StepSize = stod(argv[2]);
	Steps_Total = Steps_Start + stold(argv[3]);
	Steps_Output = stold(argv[4]);
	if (find_parameter(s_para, "MPC").compare("ON") == 0) {
		MPC_on = true;
	}

	std::cout << "blubb" << std::endl;
	int arg { };
	while (arg < argc) {
		if (strcmp(argv[arg], "MPC") == 0) {
			MPC_on = true;
			std::cout << arg << std::endl;
			if (arg +1 < argc) Shear = stod(argv[arg+1]);
			arg++;
			break;
		}
		arg++;
	}


	if (argc >= 8) {
		BoxX = stod(argv[5]);
		BoxY = stod(argv[6]);
		BoxZ = stod(argv[7]);
	}



	std::cout << "Type A: " << TypeA << " Type B: " << TypeB << " Arms: " << Arms << " Lambda: " << Lambda << std::endl;
	std::cout << "Temperature: " << Temperature <<  std::endl;
	std::cout << "Box Size: " << BoxX << " " << BoxY << " " << BoxZ << std::endl;
	std::cout << "Step Size: " << StepSize << std::endl;
	std::cout << "Start at: " << Steps_Start << " Stop at: " << Steps_Total << " Output every: " << Steps_Output << std::endl;
	if (MPC_on) {
		std::cout << "MPC is turned ON with shear rate: " << Shear << std::endl;
	}
	else std::cout << "MPC is turned OFF" << std::endl;



	ss_para_new.str(std::string());
	ss_para_new.precision(0);
	ss_para_new << "_Star";
	ss_para_new << "_A" << TypeA;
	ss_para_new << "_B" << TypeB;
	ss_para_new << "_Arms" << Arms;
	ss_para_new << "_Lx" << BoxX;
	ss_para_new << "_Ly" << BoxY;
	ss_para_new << "_Lz" << BoxZ;
	ss_para_new.precision(3);
	ss_para_new << "_Lambda" << Lambda;
	ss_para_new << "_T" << Temperature;
	ss_para_new << "_run" << scientific << Steps_Total;
	if (MPC_on) ss_para_new << "_MPCON_Shear" << Shear;
	else ss_para_new << "_MPCOFF";

	ofstream statistic_file { };
	FILE* config_file { };
	string oldname = "./results/statistics"+ss_para.str()+".dat";
	string newname = "./results/statistics"+ss_para_new.str()+".dat";
	std::cout << oldname << std::endl;
	std::cout << newname << std::endl;
	rename(oldname.c_str(), newname.c_str());
	string statistic_file_name = newname;
	oldname = "./results/config"+ss_para.str()+".pdb";
	newname = "./results/config"+ss_para_new.str()+".pdb";
	rename(oldname.c_str(), newname.c_str());
	string config_file_name = newname;
	statistic_file.open(statistic_file_name, ios::out | ios::app);
	config_file = fopen(config_file_name.c_str(), "a");

	Box box(BoxX, BoxY, BoxZ, Temperature, Lambda);


	if (argc > 1 && strcmp(argv[1], "Chain") == 0) {
		box.add_chain(TypeA, TypeB, 10.);
		std::cout << "building a chain" << std::endl;
	}
	else	 {
		box.add_star(std::string(argv[1]), TypeA, TypeB, Arms, 10.);
		std::cout << "building a star" << std::endl;
	}



	if (MPC_on) {
		thermostat = new Thermostat_None{ box, StepSize };
		hydrodynamics = new MPC{box, Temperature, Shear};

	}
	else {
		thermostat = new Andersen{box, StepSize, Temperature, 1999};
		hydrodynamics = new Hydrodynamics_None{box};
	}



	if (MPC_on) hydrodynamics -> initialize();
	clock_t begin = clock();

	std::cout << thermostat -> info() << std::endl;
	box.print_molecules(std::cout);

	for (long int n = Steps_Start + 1; n <= Steps_Total; ++n) {


		if (!(n%Steps_Output)) {
			thermostat -> propagate(true);
			std::cout << n << " ";
			box.print_Epot(std::cout);
			box.print_Ekin(std::cout);
			if (MPC_on) std::cout << hydrodynamics -> calculateCurrentTemperature() << " ";
			else box.print_Temperature(std::cout);
			std::list<unsigned> patches = box.calculate_patches();
			int number_of_patches {0};
			double av_patch_size {0.0};
			for (auto& element : patches) {
				if (element > 1) {
					number_of_patches++;
					av_patch_size += element;
				}
				//std::cout << element << ' ';
			}
			if (number_of_patches > 0) av_patch_size /= number_of_patches;
			Matrix3d gyr_tensor = box.calculate_gyration_tensor();
			std::cout << '\n';
			box.print_PDB(config_file, n);
			statistic_file << n << " ";
			box.print_Epot(statistic_file);
			box.print_Ekin(statistic_file);
			box.print_Temperature(statistic_file);
			box.print_radius_of_gyration(statistic_file);
			statistic_file << number_of_patches << " " << av_patch_size << " ";
			for (int i = 0; i < gyr_tensor.size(); i++) {
				statistic_file << *(gyr_tensor.data()+i) << " ";
			}
			statistic_file << "\n";
			//std::cout << '\n';
		}
		else thermostat -> propagate(false);
		if (MPC_on && !(n%100)) {
			hydrodynamics -> step(0.1);
		}
	}

	FILE* end_config_file { };
	string end_config_file_name = "./results/end_config"+ss_para_new.str()+".pdb";
	end_config_file = fopen(end_config_file_name.c_str(), "w");
	box.print_PDB(end_config_file, Steps_Total);


	clock_t end = clock();
	//box.print_molecules(std::cout);
	std::cout << "time: " << double(end-begin)/CLOCKS_PER_SEC << std::endl;

}
예제 #3
0
파일: c_world.cpp 프로젝트: rfree2/antinet
void c_world::load (const string &filename) {
	ifstream input_file(filename);

	const int line_max_size = 8192;
	char line[line_max_size];

	string str_line;
	t_pos x, y;
	t_cjdaddr address;
	string type, name;
	while (input_file.getline(line, line_max_size)) {
		str_line = move(string(line));
		//std::cout << str_line << std::endl;
		if (str_line.find('{') != std::string::npos && str_line.find("connections") == std::string::npos) { // TODO sections
			str_line.erase(0, 4); // 4 characters
			str_line.erase(str_line.end() - 2); // TODO
			str_line.erase(str_line.end() - 1); // TODO
			type = std::move(str_line);
		} else if (str_line.find('x') != std::string::npos) {
			x = stol(str_line.substr(2));
		} else if (str_line.find('y') != std::string::npos) {
			y = stol(str_line.substr(2));
		} else if (str_line.find("name") != std::string::npos) {
			name = std::move(str_line.substr(5));
		} else if (str_line.find("IP") != std::string::npos) {
			address = stol(str_line.substr(3));
		} else if (str_line.find('}') != std::string::npos) { // save to vector
			if (type == "cjddev")
				m_objects.push_back(make_shared<c_cjddev>(name, x, y, address));
			else if (type == "tnetdev")
				m_objects.push_back(make_shared<c_tnetdev>(name, x, y, address));
			else if (type == "userdev")
				m_objects.push_back(make_shared<c_userdev>(name, x, y, address));
		} else if (str_line.find("connections") != std::string::npos) {
			while (input_file.getline(line, line_max_size) || str_line.find('}') != std::string::npos) {
				str_line = move(string(line));
				if (str_line.find("=>") != std::string::npos) {
					istringstream ss;
					ss.str(str_line);
					t_cjdaddr ip_1, ip_2;
					ss >> ip_1;
					string tmp;
					ss >> tmp; // "=>"
					ss >> ip_2;
					unsigned int price;
					ss >> price;
					shared_ptr<c_cjddev> node_1;
					shared_ptr<c_cjddev> node_2;
					for (auto node : m_objects) {
						shared_ptr<c_cjddev> node_ptr = std::dynamic_pointer_cast<c_cjddev>(node);
						if (node_ptr->get_address() == ip_1) {
							node_1 = node_ptr;
						} else if (node_ptr->get_address() == ip_2) {
							node_2 = node_ptr;
						}
						if (node_1 && node_2) {
							node_1->add_neighbor(node_2, price);
							node_1.reset();
							node_2.reset();
						}
					}
				}
			}
		}
	}
예제 #4
0
	KPIECE(const Workspace &workspace, const Agent &agent, const InstanceFileMap &args) :
		workspace(workspace), agent(agent), goalEdge(NULL), samplesGenerated(0), edgesAdded(0), edgesRejected(0) {

		collisionCheckDT = args.doubleVal("Collision Check Delta t");
		dfpair(stdout, "collision check dt", "%g", collisionCheckDT);

		const typename Workspace::WorkspaceBounds &agentStateVarRanges = agent.getStateVarRanges(workspace.getBounds());
		stateSpaceDim = agentStateVarRanges.size();

		StateSpace *baseSpace = new StateSpace(stateSpaceDim);
		ompl::base::RealVectorBounds bounds(stateSpaceDim);
		for(unsigned int i = 0; i < stateSpaceDim; ++i) {
			bounds.setLow(i, agentStateVarRanges[i].first);
			bounds.setHigh(i, agentStateVarRanges[i].second);
		}
		baseSpace->setBounds(bounds);
		ompl::base::StateSpacePtr space = ompl::base::StateSpacePtr(baseSpace);

		const std::vector< std::pair<double, double> > &controlBounds = agent.getControlBounds();
		controlSpaceDim = controlBounds.size();

		ompl::control::RealVectorControlSpace *baseCSpace = new ompl::control::RealVectorControlSpace(space, controlSpaceDim);
		ompl::base::RealVectorBounds cbounds(controlSpaceDim);
		for(unsigned int i = 0; i < controlSpaceDim; ++i) {
			cbounds.setLow(i, controlBounds[i].first);
			cbounds.setHigh(i, controlBounds[i].second);
		}

		baseCSpace->setBounds(cbounds);
		ompl::control::ControlSpacePtr cspace(baseCSpace);

		// construct an instance of  space information from this control space
		spaceInfoPtr = ompl::control::SpaceInformationPtr(new ompl::control::SpaceInformation(space, cspace));

		// set state validity checking for this space
		spaceInfoPtr->setStateValidityChecker(boost::bind(&KPIECE::isStateValid, this, spaceInfoPtr.get(), _1));

		// set the state propagation routine
		spaceInfoPtr->setStatePropagator(boost::bind(&KPIECE::propagate, this, _1, _2, _3, _4));

		pdef = ompl::base::ProblemDefinitionPtr(new ompl::base::ProblemDefinition(spaceInfoPtr));

		spaceInfoPtr->setPropagationStepSize(args.doubleVal("Steering Delta t"));
		dfpair(stdout, "steering dt", "%g", args.doubleVal("Steering Delta t"));
		spaceInfoPtr->setMinMaxControlDuration(stol(args.value("KPIECE Min Control Steps")),stol(args.value("KPIECE Max Control Steps")));
		dfpair(stdout, "min control duration", "%u", stol(args.value("KPIECE Min Control Steps")));
		dfpair(stdout, "max control duration", "%u", stol(args.value("KPIECE Max Control Steps")));

		spaceInfoPtr->setup();

		kpiece = new ompl::control::KPIECE1(spaceInfoPtr);

		kpiece->setGoalBias(args.doubleVal("KPIECE Goal Bias"));
		dfpair(stdout, "goal bias", "%g", args.doubleVal("KPIECE Goal Bias"));

		kpiece->setBorderFraction(args.doubleVal("KPIECE Border Fraction"));
		dfpair(stdout, "border fraction", "%g", args.doubleVal("KPIECE Border Fraction"));

		kpiece->setCellScoreFactor(args.doubleVal("KPIECE Cell Score Good"), args.doubleVal("KPIECE Cell Score Bad"));
		dfpair(stdout, "cell score good", "%g", args.doubleVal("KPIECE Cell Score Good"));
		dfpair(stdout, "cell score bad", "%g", args.doubleVal("KPIECE Cell Score Bad"));

		kpiece->setMaxCloseSamplesCount(stol(args.value("KPIECE Max Close Samples")));
		dfpair(stdout, "max closed samples", "%u", stol(args.value("KPIECE Max Close Samples")));


		ompl::base::RealVectorRandomLinearProjectionEvaluator *projectionEvaluator = new ompl::base::RealVectorRandomLinearProjectionEvaluator(baseSpace, stateSpaceDim);

		ompl::base::ProjectionEvaluatorPtr projectionPtr = ompl::base::ProjectionEvaluatorPtr(projectionEvaluator);

		kpiece->setProjectionEvaluator(projectionPtr);
	}
예제 #5
0
 seconds Settings::get_default_queue_redelivery_interval( void ) const
 {
     const auto value = restbed::Settings::get_property( "redelivery-interval" );
     
     return ( value.empty( ) ) ? seconds( 30 ) : seconds( stol( value ) );
 }
예제 #6
0
int main(int ac, char* av[]) {
    po::options_description od_desc("Allowed options");
    get_options_description(od_desc);
    
    po::variables_map vm;
    po::store(po::parse_command_line(ac, av, od_desc), vm);
    if (vm.count("help")) {
       std::cout << od_desc << "\n"; 
       return 0;
    }

    try{
      po::notify(vm);
    }
    catch(...){
	std::cout << od_desc << "\n"; 
	return 0;	
    } 

    auto ret_val = process_command_line(vm, od_desc);
    if (ret_val != 2) return ret_val;


    auto db_dbase(vm["dbname"].as<std::string>());
    db_dbase = "dbname = " + db_dbase;
    auto db_host(vm["host"].as<std::string>());
    auto db_port(vm["port"].as<std::string>());
    auto db_username(vm["username"].as<std::string>());
    auto db_pwd(vm["password"].as<std::string>());
    auto test(vm["test"].as<bool>());
    //auto db_no_pwd(vm["no-password"].as<std::string>());

    const char *conninfo = db_dbase.c_str();
    PGconn     *conn;
    PGresult   *res;
    int rec_count, col_count;


    conn = PQconnectdb(conninfo);
 /* Check to see that the backend connection was successfully made */
    if (PQstatus(conn) != CONNECTION_OK)
    {
        fprintf(stderr, "Connection to database failed: %s",
                PQerrorMessage(conn));
        exit_nicely(conn);
        exit(0);
    }

   std::string data_sql;
   if (test) {
     data_sql = "select id, source, target, cost, -1 as reverse_cost  from table1 order by id";
     // data_sql = "select id, source, target, cost, reverse_cost from edge_table order by id";
   } else {
     std::cout << "Input data query: ";
     std::getline (std::cin,data_sql);
   }
   std::cout << "\nThe data is from:" << data_sql <<"\n";

   res = PQexec(conn, data_sql.c_str());

      if (PQresultStatus(res) != PGRES_TUPLES_OK) {
        std::cout << "We did not get any data!\n";
        exit_nicely(conn);
        exit(1);
      }

      rec_count = PQntuples(res);
      col_count = PQnfields(res);
      if (col_count > 5 || col_count < 4) {
        std::cout << "Max number of columns 5\n";
        std::cout << "Min number of columns 4\n";
        exit_nicely(conn);
        exit(1);
      }

      auto id_fnum = PQfnumber(res, "id");
      auto source_fnum = PQfnumber(res, "source");
      auto target_fnum = PQfnumber(res, "target");
      auto cost_fnum = PQfnumber(res, "cost");
      auto reverse_fnum = PQfnumber(res, "reverse_cost");



      pgr_edge_t *data_edges;
      data_edges = (pgr_edge_t *) malloc(rec_count * sizeof(pgr_edge_t));
	

      printf("We received %d records.\n", rec_count);
      puts("==========================");

      

      std::string::size_type sz;
      std::string str;

      for (int row = 0; row < rec_count; ++row) {
        str = std::string(PQgetvalue(res, row, id_fnum));
        data_edges[row].id = stol(str, &sz);

        str = std::string(PQgetvalue(res, row, source_fnum));
        data_edges[row].source = stol(str, &sz);

        str = std::string(PQgetvalue(res, row, target_fnum));
        data_edges[row].target = stol(str, &sz);

        str = std::string(PQgetvalue(res, row, cost_fnum));
        data_edges[row].cost = stod(str, &sz);

        if (reverse_fnum != -1) {
          str = std::string(PQgetvalue(res, row, reverse_fnum));
          data_edges[row].reverse_cost = stod(str, &sz);
        } 
#if 0
        std::cout << "\tid: " << data_edges[row].id << "\t";
        std::cout << "\tsource: " << data_edges[row].source << "\t";
        std::cout << "\ttarget: " << data_edges[row].target << "\t";
        std::cout << "\tcost: " << data_edges[row].cost << "\t";
        if (reverse_fnum != -1) {
          std::cout << "\treverse: " << data_edges[row].reverse_cost << "\t";
        }
        std::cout << "\n";
#endif
      }


      puts("==========================");

      PQclear(res);

      PQfinish(conn);


//////////////////////  END READING DATA FROM DATABASE ///////////////////

    std::string directed;
    std::cout << "Is the graph directed [N,n]? default[Y]";
    std::getline(std::cin,directed);
    graphType gType =  (directed.compare("N")==0 || directed.compare("n")==0)? UNDIRECTED: DIRECTED;
    bool directedFlag =  (directed.compare("N")==0 || directed.compare("n")==0)? false: true;


    const int initial_size = rec_count;

    
    Pgr_base_graph< DirectedGraph > digraph(gType, initial_size);
    Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size);
    
    if (directedFlag) {
      process(digraph, data_edges, rec_count);
    } else {
      process(undigraph, data_edges, rec_count);
    }

}
예제 #7
0
int main(
  int argc,
  char **argv
)
{
    register int c;
    bool showusage = FALSE;                     /* usage error? */
    int rc = 0;
    FILE *outfp, *infp;

    /*
     * figure out invocation leaf-name
     */

    if ((progname = strrchr(argv[0], '/')) == (char *) NULL)
        progname = argv[0];
    else
        progname++;

    argv[0] = progname;                         /* for getopt err reporting */

    /*
     *  Check options and arguments.
     */

    progname = argv[0];
    while ((c = getopt(argc, argv, "F:a:o:vl")) != EOF)
        switch (c)
        {
            case 'a':                           /* base address */
                base = stol(optarg);
                break;

            case 'l':                           /* linear output */
                linear = TRUE;
                break;

            case 'v':                           /* toggle verbose */
                verbose = ! verbose;
                break;

            case 'o':                           /* output file */
                outfilename = optarg;
                break;

            case 'F':                           /* 0xFF fill amount (bytes) */
                FFfill = stol(optarg) * 1024L / 8L;
                break;

            case '?':
                showusage = TRUE;
        }

    if (showusage)
    {
        (void) fprintf(stderr, "%s", USAGE);
        exit(1);
    }

    if (linear && (base != 0))
    {
        error(0, "-l and -a may not be specified in combination");
        exit(1);
    }

    if (STREQ(outfilename, "-"))
    {
        outfp = stdout;
        outfilename = "stdout";
    }
    else
        if ((outfp = fopen(outfilename, "w")) == (FILE *) NULL)
        {
            error(-1, "couldn't open '%s' for output", outfilename);
            exit(1);
        }

    /*
     * Now process the input files (or stdin, if none specified)
     */

    if (argv[optind] == (char *) NULL)          /* just stdin */
        exit(unhex(stdin, "stdin", outfp, outfilename));
    else
        for (; (optarg = argv[optind]); optind++)
        {
            if (STREQ(optarg, "-"))
                rc += unhex(stdin, "stdin", outfp, outfilename);
            else
            {
                if ((infp = fopen(optarg, "r")) == (FILE *) NULL)
                {
                    error(-1, "couldn't open '%s' for input", optarg);
                    exit(1);
                }
                rc += unhex(infp, optarg, outfp, outfilename);
            }
        }

    return(rc);
}
예제 #8
0
 long stol(Iterable &object)
 {
   return stol(std::begin(object), std::end(object));
 }
예제 #9
0
void CodeWriter::WriteCom(trivec tvec)
{
	m_sCom = tvec.first;
	m_sArg1 = tvec.second.first;
	m_sArg2 = tvec.second.second;

		if(m_sCom ==  "push") 
    {
				if(m_sArg1 == "constant") 
				{
          // @2
          // D=A
          // @SP
          // A=M
          // M=D   (*sp) = 2
          // @SP
          // M=M-1 (sp = sp-1)
					m_ofs << "@" << m_sArg2 << endl;
					m_ofs << "D=A" << endl;
					m_ofs << "@" << SP << endl;
          m_ofs << "A=M" << endl;
					m_ofs << "M=D" << endl;
          m_ofs << "@SP" << endl;
          m_ofs << "M=M-1" << endl;
				}
        else if(m_sArg1 ==  "static") 
				{
					if(IsNum(m_sArg2))
						m_ofs << "@" << STATIC(0) + stol(m_sArg2) << endl;
					else
						cout << "push a symbol address of static segment" << endl;
					m_ofs << "D=M" << endl;
					m_ofs << "@" << SP << endl;
					m_ofs << "M=D" << endl;
				}

        else if( m_sArg1 == "local")
				{
					//@LCL  (push local 2)
					//A=M
					//A=A+1
          				//A=A+1  //DO IT TWICE
					//D=M
					//@SP
					//A=M
          				//M=D
					m_ofs << "@" << "LCL"  << endl;
					m_ofs << "A=M" << endl;

					if(IsNum(m_sArg2))
            {
              int n = stol(m_sArg2);
              for(int i=0;i<n;++i)
                m_ofs << "A=A+1" << endl;
            }
					else
						cout << "push a symbol address of local,temp,argument segment" << endl;

					m_ofs << "D=M" << endl;
					m_ofs << "@" << SP << endl;
          m_ofs << "A=M" << endl;
					m_ofs << "M=D" << endl;
				}
				
        else if(m_sArg1 == "argument" )
				{				
					//@ARG  (push argument 2)
					//A=M
					//A=A+1
          //A=A+1  //DO IT TWICE
					//D=M
					//@SP
					//A=M
          //M=D
					m_ofs << "@" << "ARG"  << endl;
					m_ofs << "A=M" << endl;

					if(IsNum(m_sArg2))
            {
              int n = stol(m_sArg2);
              for(int i=0;i<n;++i)
                m_ofs << "A=A+1" << endl;
            }
					else
						cout << "push a symbol address of local,temp,argument segment" << endl;

					m_ofs << "D=M" << endl;
					m_ofs << "@" << SP << endl;
          m_ofs << "A=M" << endl;
					m_ofs << "M=D" << endl;
      }
      else if (m_sArg1 == "this")
      {
      //@ARG  (push argument 2)
					//A=M
					//A=A+1
          //A=A+1  //DO IT TWICE
					//D=M
					//@SP
					//A=M
          //M=D
					m_ofs << "@" << "THIS"  << endl;
					m_ofs << "A=M" << endl;

					if(IsNum(m_sArg2))
            {
              int n = stol(m_sArg2);
              for(int i=0;i<n;++i)
                m_ofs << "A=A+1" << endl;
            }
					else
						cout << "push a symbol address of local,temp,argument segment" << endl;

					m_ofs << "D=M" << endl;
					m_ofs << "@" << SP << endl;
          m_ofs << "A=M" << endl;
					m_ofs << "M=D" << endl;
}
      else if (m_sArg1 == "that" )
      {
          //@THAT  (push argument 2)
					//A=M
					//A=A+1
          //A=A+1  //DO IT TWICE
					//D=M
					//@SP
					//A=M
          //M=D
					m_ofs << "@" << "THAT"  << endl;
					m_ofs << "A=M" << endl;

					if(IsNum(m_sArg2))
            {
              int n = stol(m_sArg2);
              for(int i=0;i<n;++i)
                m_ofs << "A=A+1" << endl;
            }
					else
						cout << "push a symbol address of local,temp,argument segment" << endl;

					m_ofs << "D=M" << endl;
					m_ofs << "@" << SP << endl;
          m_ofs << "A=M" << endl;
					m_ofs << "M=D" << endl;
}
    } //switch(m_Arg1)

    else if(m_sCom == "pop") 
    {
					if(m_sArg1 == "static")  // pop static 1
					{
						// @SP
						// D=M
						// @STATIC+2
						// M=D
						// D=D-1 stack pointer deccrement
						// @SP
						// M=D
              m_ofs << "@SP" << endl;
							m_ofs << "D=M" << endl;
							if(IsNum(m_sArg2))
								m_ofs << "@" << STATIC(0) + stol(m_sArg2) << endl;
							else
								cout << "pop a symbol address" << endl;
							m_ofs << "M=D" << endl;
							m_ofs << "D=D-1" << endl;
							m_ofs << "@SP" << endl;
							m_ofs << "M=D" << endl;
					}

          else if(m_sArg1 == "constant")
					{
						// pop constant 2
						// @SP
						// D=M
						// D=D-1
						// @SP
						// M=D
						m_ofs << "@SP" << endl;
						m_ofs << "D=M" << endl;
						m_ofs << "D=D-1" << endl;
						m_ofs << "@SP" << endl;
						m_ofs << "M=D" << endl;
					}

          else if( m_sArg1 ==  "local")
					{
						// pop local 2
						// @SP
            // A=M
            // A=A+1
            // D=M
            // @LCL
            // A=M
            // A=A+1
            // A=A+1  //twice
            // M=D
					m_ofs << "@" << "ARG"  << endl;
					m_ofs << "A=M" << endl;

					if(IsNum(m_sArg2))
            {
              int n = stol(m_sArg2);
              for(int i=0;i<n;++i)
                m_ofs << "A=A+1" << endl;
            }
					else
						cout << "push a symbol address of local,temp,argument segment" << endl;

					m_ofs << "D=M" << endl;
					m_ofs << "@" << "SP" << endl;
          m_ofs << "a=m" << endl;
					m_ofs << "m=d" << endl;
//
				  }
			}// (pop)
    else if(m_sCom == "add")
    {
      //@SP
      //A=M
      //A=A+1
      //D=M    get mem(stackpointer)
      //A=A+1
      //D=D+M  add *sp+*(sp+1)
      //M=D    save into *(sp+1)
      //@SP
      //M=M+1  sp = sp +1
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=D+M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
    }
    else if(m_sCom == "sub")
    {
      //@SP
      //A=M
      //A=A+1  (SP -> first unallocated mem)
      //D=M    get mem(stackpointer)
      //A=A+1
      //D=M-D  sub *(sp+1)-*(sp)
      //M=D    save into *(sp+1)
      //@SP
      //M=M+1  sp = sp +1
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M-D" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
//
    }
    else if(m_sCom == "neg")
    {
      //@SP
      //A=M
      //A=A+1
      //M=-M
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "M=-M" << endl;
    }
    else if(m_sCom == "eq")
    {
      // @SP
      // A=M
      // A=A+1
      // D=M
      // A=A+1
      // D=M-D
      // @TRUE100
      // D;JEQ  //D=0;JUMP TRUE
      // @SP
      // M=M+1
      // @SP
      // M=M+1
      // @0
      // D=A  PUSH 0
      // @SP
      // M=D
      // @SP
      // M=M-1 
      // @END100
      // 0;JMP
      // (TRUE100)
      // @SP
      // M=M+2
      // @65535
      // D=A  PUSH 1111 1111 1111 1111
      // @SP
      // M=M-1
      // (END100)
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M-D" << endl;
      m_ofs << "@TRUE" << m_truetag << endl;
      m_ofs << "D;JEQ" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@0" << endl;
      m_ofs << "D=A" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M-1" << endl;
      m_ofs << "@END" << m_endtag << endl;
      m_ofs << "0;JMP" << endl;
      m_ofs << "(TRUE" << m_truetag++ << ")" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@65535" << endl;
      m_ofs << "D=A" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M-1" << endl;
      m_ofs << "(END" << m_endtag++ << ")" << endl;

    } 
    else if (m_sCom == "gt" )
    {
      // @SP
      // A=M
      // A=A+1
      // D=M
      // A=A+1
      // D=M-D
      // @TRUE100
      // D;JGT  //D=0;JUMP TRUE
      // @SP
      // M=M+2 
      // @0
      // D=A  PUSH 0
      // @SP
      // M=D
      // @SP
      // M=M-1 
      // @END100
      // 0;JMP
      // (TRUE100)
      // @SP
      // M=M+2
      // @65535
      // D=A  PUSH 1111 1111 1111 1111
      // @SP
      // M=M-1
      // (END100)
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M-D" << endl;
      m_ofs << "@TRUE" << m_truetag << endl;
      m_ofs << "D;JGT" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@0" << endl;
      m_ofs << "D=A" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M-1" << endl;
      m_ofs << "@END" << m_endtag << endl;
      m_ofs << "0;JMP" << endl;
      m_ofs << "(TRUE" << m_truetag++ << ")" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@SP"  << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@65535" << endl;
      m_ofs << "D=A" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M-1" << endl;
      m_ofs << "(END" << m_endtag++ << ")" << endl;


    }
    else if (m_sCom == "lt" )
    {
      // @SP
      // A=M
      // A=A+1
      // D=M
      // A=A+1
      // D=M-D
      // @TRUE100
      // D;JLT  //D=0;JUMP TRUE
      // @SP
      // M=M+2 
      // @0
      // D=A  PUSH 0
      // @SP
      // M=D
      // @SP
      // M=M-1 
      // @END100
      // 0;JMP
      // (TRUE100)
      // @SP
      // M=M+2
      // @65535
      // D=A  PUSH 1111 1111 1111 1111
      // @SP
      // M=M-1
      // (END100)
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M"  << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M-D" << endl;
      m_ofs << "@TRUE" << m_truetag << endl;
      m_ofs << "D;JLT" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@0" << endl;
      m_ofs << "D=A" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M-1" << endl;
      m_ofs << "@END" << m_endtag << endl;
      m_ofs << "0;JMP" << endl;
      m_ofs << "(TRUE" << m_truetag++ << ")" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
      m_ofs << "@65535" << endl;
      m_ofs << "D=A" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M-1" << endl;
      m_ofs << "(END" << m_endtag++ << ")" << endl;
    }
    else if (m_sCom == "and")
    {
      //@SP
      //A=M
      //A=A+1  (SP -> first unallocated mem)
      //D=M    get mem(stackpointer)
      //A=A+1
      //D=M-D  sub *(sp+1)-*(sp)
      //M=D    save into *(sp+1)
      //@SP
      //M=M+1  sp = sp +1
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=D&M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;

    }
    else if (m_sCom == "or")
    {
      //@SP
      //A=M
      //A=A+1  (SP -> first unallocated mem)
      //D=M    get mem(stackpointer)
      //A=A+1
      //D=M-D  sub *(sp+1)-*(sp)
      //M=D    save into *(sp+1)
      //@SP
      //M=M+1  sp = sp +1
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "D=D|M" << endl;
      m_ofs << "M=D" << endl;
      m_ofs << "@SP" << endl;
      m_ofs << "M=M+1" << endl;
    }
    else if(m_sCom == "not")
    {
      //@SP
      //A=M
      //A=A+1
      //M=!M
      m_ofs << "@SP" << endl;
      m_ofs << "A=M" << endl;
      m_ofs << "A=A+1" << endl;
      m_ofs << "M=!M" << endl;
    }



	}// WriteCom
예제 #10
0
prvreader::PrvEvent* prvreader::PrvParser::parseCommunications(tokenizer<escaped_list_separator<char> > *tokens, long lineNumber)
{
    if (filter->getDisableCommunications()){
        return new PrvOther(lineNumber, prveventtype::Filtered);
    }
    tokenizer<escaped_list_separator<char> >::iterator tokensIterator=tokens->begin();
    tokensIterator++;
    string temp=*tokensIterator;
    tokensIterator++;
    int cpu1=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    int app1=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    int task1=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    int thread1=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    long startTimestampSW=stol(temp);
    temp=*tokensIterator;
    tokensIterator++;
    long startTimestampHW=stol(temp);
    temp=*tokensIterator;
    tokensIterator++;
    int cpu2=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    int app2=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    int task2=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    int thread2=atoi(temp.c_str());
    temp=*tokensIterator;
    tokensIterator++;
    long endTimestampHW=stol(temp);
    temp=*tokensIterator;
    tokensIterator++;
    long endTimestampSW=stol(temp);
    temp=*tokensIterator;
    if (!fast){
        if (cpu1==0){
            Message::Warning("line "+ to_string(lineNumber)+". CPU value is 0. Event will be dropped...");
            return new PrvOther(lineNumber, prveventtype::NotConform);
        }
        if (cpu2==0){
            Message::Warning("line "+ to_string(lineNumber)+". CPU value is 0. Event will be dropped...");
            return new PrvOther(lineNumber, prveventtype::NotConform);
        }
    }
    if (currentTimestamp>startTimestampHW){
        Message::Critical("line "+ to_string(lineNumber)+". Events are not correctly time-sorted. Current timestamp: "+ to_string(startTimestampHW)+" Previous timestamp: "+to_string(currentTimestamp)+". Leaving...");
        return new PrvOther(lineNumber, prveventtype::Critical);
    }
    /*if (startTimestampHW<startTimestampSW){
        return new PrvOther(lineNumber, prveventtype::NotConform);
    }*/
    currentTimestamp=startTimestampHW;
    //Communication tag is not retrieved. Should we?
    return new PrvCommunications(cpu1, app1, task1, thread1, startTimestampSW, lineNumber, cpu2, app2, task2, thread2, endTimestampSW, startTimestampHW, endTimestampHW, temp);
//events
}
bool NetworkServer::networkUpdate() {
	bool shouldContinue = true;
	
	checkForNewClients();
	
	// check for TCP messages
	while(true) {
		std::vector<std::string> vect = communicator.receiveTcpMessage();
		if(vect.size() == 0)
			break;
		std::string message = vect[0];
		std::string ip = vect[1];
		long timeStamp = 0;
		for(int i=0; i<message.size(); i++) {
			if(message.at(i) == '@') {
				timeStamp = stol(message.substr(0, i));
				message = message.substr(i+1);
				break;
			}
		}
		if(message.at(0) == '_') {
			message = message.substr(1);
			if(message.substr(0, 7) == "CONNECT") {
				unsigned short newUdpPort = stoi(message.substr(7));
				for(int i=0; i<clients.size(); i++) {
					if(clients[i].ip.toString() == ip)
						clients[i].udpPort = newUdpPort;
				}
			}
		}
		else {
			shouldContinue = shouldContinue && receivedTcp(message, sf::IpAddress(ip), timeStamp);
			if(!shouldContinue)
				return shouldContinue;
		}
	}
	
	// check for UDP messages
	while(true) {
		char buffer[1024];
		char *begin = buffer;
		char *end = begin + sizeof(buffer);
		std::fill(begin, end, 0);
		std::size_t received = 0;
		sf::IpAddress sender;
		unsigned short port;
		udpSocket.receive(buffer, sizeof(buffer), received, sender, port);
		std::string message = std::string(buffer);
		long timeStamp = 0;
		for(int i=0; i<message.size(); i++) {
			if(message.at(i) == '@') {
				timeStamp = stol(message.substr(0, i));
				message = message.substr(i+1);
				break;
			}
		}
		if(message != "") {
			if(message.at(0) == '_')
				sendUdp("_PING___" + std::to_string(timeStamp), sender);
			else
				receivedUdp(message, sender, timeStamp);
		}
		else
			break;
	}
	
	return shouldContinue;
}
예제 #12
0
파일: conv.hpp 프로젝트: TrygveS/sweet.hpp
	long operator()(const std::string& s) {
		return stol(s);
	}
예제 #13
0
void process_drivingDistance(G &graph, const std::vector<std::string> &tokens) {
      std::string::size_type sz;
      if (tokens[1].compare("from") != 0) {
        std::cout << "missing 'from' kewyword\n";
        return;
      }

      std::vector< int64_t > sources;
      unsigned int i_ptr = 2;

      for ( ; i_ptr < tokens.size(); ++i_ptr) {
          if (tokens[i_ptr].compare("dist") == 0) break;
          try {
            uint64_t start_vertex(stol(tokens[i_ptr], &sz));
            sources.push_back(start_vertex);
          } catch(...) {
            break;
          }
      }

      if (i_ptr == tokens.size() || tokens[i_ptr].compare("dist") != 0) {
        std::cout << "drivDist: 'dist' kewyword not found\n";
        return;
      }

      if (sources.size() == 0) {
        std::cout << "drivDist: No start value found\n";
        return;
      }

      ++i_ptr;
      if (i_ptr == tokens.size()) {
        std::cout << " 'distance' value not found\n";
        return;
      }

      double distance = stod(tokens[i_ptr], &sz);

      ++i_ptr;
      bool equiCost(false);
      if (i_ptr != tokens.size()) {
        if (tokens[i_ptr].compare("equi") != 0) {
          std::cout << " Unknown keyword '" << tokens[i_ptr] << "' found\n";
          return;
        } else {
          equiCost = true;
        }
      }

      std::cout << "found " << sources.size() << "starting locations\n";
      Pgr_dijkstra< G > fn_dijkstra;

      if (sources.size() == 1) {
        std::cout << "Performing pgr_DrivingDistance for single source\n";
        Path path;
        pgr_drivingDistance(graph, path, sources[0], distance);
        std::cout << "\t\t\tTHE OPUTPUT\n";
        std::cout << "seq\tfrom\tnode\tedge\tcost\n";
        path.print_path();
      } else {
        std::deque< Path >  paths;
        pgr_drivingDistance(graph, paths, sources, distance);
        if (equiCost == false) {
          std::cout << "Performing pgr_DrivingDistance for multiple sources\n";
          std::cout << "\t\t\tTHE OPUTPUT\n";
          std::cout << "seq\tfrom\tnode\tedge\tcost\n";
          for (const auto &path :  paths) {
            if (sizeof(path) == 0) return;  // no solution found
            path.print_path();
          }
        } else {
          std::cout << "Performing pgr_DrivingDistance for multiple sources with equi-cost\n";
          Path path = equi_cost(paths);
          std::cout << "\t\t\tTHE EquiCost OPUTPUT\n";
          std::cout << "seq\tfrom\tnode\tedge\tcost\n";
          path.print_path();
        }
      }
}
예제 #14
0
파일: eval.c 프로젝트: ChunHungLiu/uemacs
/*
 * Set a variable.
 *
 * @var: variable to set.
 * @value: value to set to.
 */
int svar(struct variable_description *var, char *value)
{
	int vnum;	/* ordinal number of var refrenced */
	int vtype;	/* type of variable to set */
	int status;	/* status return */
	int c;		/* translated character */
	char *sp;	/* scratch string pointer */

	/* simplify the vd structure (we are gonna look at it a lot) */
	vnum = var->v_num;
	vtype = var->v_type;

	/* and set the appropriate value */
	status = TRUE;
	switch (vtype) {
	case TKVAR:		/* set a user variable */
		if (uv[vnum].u_value != NULL)
			free(uv[vnum].u_value);
		sp = malloc(strlen(value) + 1);
		if (sp == NULL)
			return FALSE;
		strcpy(sp, value);
		uv[vnum].u_value = sp;
		break;

	case TKENV:		/* set an environment variable */
		status = TRUE;	/* by default */
		switch (vnum) {
		case EVFILLCOL:
			fillcol = atoi(value);
			break;
		case EVPAGELEN:
			status = newsize(TRUE, atoi(value));
			break;
		case EVCURCOL:
			status = setccol(atoi(value));
			break;
		case EVCURLINE:
			status = gotoline(TRUE, atoi(value));
			break;
		case EVRAM:
			break;
		case EVFLICKER:
			flickcode = stol(value);
			break;
		case EVCURWIDTH:
			status = newwidth(TRUE, atoi(value));
			break;
		case EVCBUFNAME:
			strcpy(curbp->b_bname, value);
			curwp->w_flag |= WFMODE;
			break;
		case EVCFNAME:
			strcpy(curbp->b_fname, value);
			curwp->w_flag |= WFMODE;
			break;
		case EVSRES:
			status = TTrez(value);
			break;
		case EVDEBUG:
			macbug = stol(value);
			break;
		case EVSTATUS:
			cmdstatus = stol(value);
			break;
		case EVASAVE:
			gasave = atoi(value);
			break;
		case EVACOUNT:
			gacount = atoi(value);
			break;
		case EVLASTKEY:
			lastkey = atoi(value);
			break;
		case EVCURCHAR:
			ldelchar(1, FALSE);	/* delete 1 char */
			c = atoi(value);
			if (c == '\n')
				lnewline();
			else
				linsert(1, c);
			backchar(FALSE, 1);
			break;
		case EVDISCMD:
			discmd = stol(value);
			break;
		case EVVERSION:
			break;
		case EVPROGNAME:
			break;
		case EVSEED:
			seed = atoi(value);
			break;
		case EVDISINP:
			disinp = stol(value);
			break;
		case EVWLINE:
			status = resize(TRUE, atoi(value));
			break;
		case EVCWLINE:
			status = forwline(TRUE, atoi(value) - getwpos());
			break;
		case EVTARGET:
			curgoal = atoi(value);
			thisflag = saveflag;
			break;
		case EVSEARCH:
			strcpy(pat, value);
			rvstrcpy(tap, pat);
#if	MAGIC
			mcclear();
#endif
			break;
		case EVREPLACE:
			strcpy(rpat, value);
			break;
		case EVMATCH:
			break;
		case EVKILL:
			break;
		case EVCMODE:
			curbp->b_mode = atoi(value);
			curwp->w_flag |= WFMODE;
			break;
		case EVGMODE:
			gmode = atoi(value);
			break;
		case EVTPAUSE:
			term.t_pause = atoi(value);
			break;
		case EVPENDING:
			break;
		case EVLWIDTH:
			break;
		case EVLINE:
			putctext(value);
		case EVGFLAGS:
			gflags = atoi(value);
			break;
		case EVRVAL:
			break;
		case EVTAB:
			tabmask = atoi(value) - 1;
			if (tabmask != 0x07 && tabmask != 0x03)
				tabmask = 0x07;
			curwp->w_flag |= WFHARD;
			break;
		case EVOVERLAP:
			overlap = atoi(value);
			break;
		case EVSCROLLCOUNT:
			scrollcount = atoi(value);
			break;
		case EVSCROLL:
#if SCROLLCODE
			if (!stol(value))
				term.t_scroll = NULL;
#endif
			break;
		}
		break;
	}
	return status;
}
예제 #15
0
파일: eval.c 프로젝트: ChunHungLiu/uemacs
/*
 * Evaluate a function.
 *
 * @fname: name of function to evaluate.
 */
char *gtfun(char *fname)
{
	int fnum;	/* index to function to eval */
	int status;	/* return status */
	char *tsp;	/* temporary string pointer */
	char arg1[NSTRING];	/* value of first argument */
	char arg2[NSTRING];	/* value of second argument */
	char arg3[NSTRING];	/* value of third argument */
	static char result[2 * NSTRING];	/* string result */

	/* look the function up in the function table */
	fname[3] = 0;		/* only first 3 chars significant */
	mklower(fname);		/* and let it be upper or lower case */
	for (fnum = 0; fnum < ARRAY_SIZE(funcs); fnum++)
		if (strcmp(fname, funcs[fnum].f_name) == 0)
			break;

	/* return errorm on a bad reference */
	if (fnum == ARRAY_SIZE(funcs))
		return errorm;

	/* if needed, retrieve the first argument */
	if (funcs[fnum].f_type >= MONAMIC) {
		if ((status = macarg(arg1)) != TRUE)
			return errorm;

		/* if needed, retrieve the second argument */
		if (funcs[fnum].f_type >= DYNAMIC) {
			if ((status = macarg(arg2)) != TRUE)
				return errorm;

			/* if needed, retrieve the third argument */
			if (funcs[fnum].f_type >= TRINAMIC)
				if ((status = macarg(arg3)) != TRUE)
					return errorm;
		}
	}


	/* and now evaluate it! */
	switch (fnum) {
	case UFADD:
		return itoa(atoi(arg1) + atoi(arg2));
	case UFSUB:
		return itoa(atoi(arg1) - atoi(arg2));
	case UFTIMES:
		return itoa(atoi(arg1) * atoi(arg2));
	case UFDIV:
		return itoa(atoi(arg1) / atoi(arg2));
	case UFMOD:
		return itoa(atoi(arg1) % atoi(arg2));
	case UFNEG:
		return itoa(-atoi(arg1));
	case UFCAT:
		strcpy(result, arg1);
		return strcat(result, arg2);
	case UFLEFT:
		return strncpy(result, arg1, atoi(arg2));
	case UFRIGHT:
		return (strcpy(result,
			       &arg1[(strlen(arg1) - atoi(arg2))]));
	case UFMID:
		return (strncpy(result, &arg1[atoi(arg2) - 1],
				atoi(arg3)));
	case UFNOT:
		return ltos(stol(arg1) == FALSE);
	case UFEQUAL:
		return ltos(atoi(arg1) == atoi(arg2));
	case UFLESS:
		return ltos(atoi(arg1) < atoi(arg2));
	case UFGREATER:
		return ltos(atoi(arg1) > atoi(arg2));
	case UFSEQUAL:
		return ltos(strcmp(arg1, arg2) == 0);
	case UFSLESS:
		return ltos(strcmp(arg1, arg2) < 0);
	case UFSGREAT:
		return ltos(strcmp(arg1, arg2) > 0);
	case UFIND:
		return strcpy(result, getval(arg1));
	case UFAND:
		return ltos(stol(arg1) && stol(arg2));
	case UFOR:
		return ltos(stol(arg1) || stol(arg2));
	case UFLENGTH:
		return itoa(strlen(arg1));
	case UFUPPER:
		return mkupper(arg1);
	case UFLOWER:
		return mklower(arg1);
	case UFTRUTH:
		return ltos(atoi(arg1) == 42);
	case UFASCII:
		return itoa((int) arg1[0]);
	case UFCHR:
		result[0] = atoi(arg1);
		result[1] = 0;
		return result;
	case UFGTKEY:
		result[0] = tgetc();
		result[1] = 0;
		return result;
	case UFRND:
		return itoa((ernd() % abs(atoi(arg1))) + 1);
	case UFABS:
		return itoa(abs(atoi(arg1)));
	case UFSINDEX:
		return itoa(sindex(arg1, arg2));
	case UFENV:
#if	ENVFUNC
		tsp = getenv(arg1);
		return tsp == NULL ? "" : tsp;
#else
		return "";
#endif
	case UFBIND:
		return transbind(arg1);
	case UFEXIST:
		return ltos(fexist(arg1));
	case UFFIND:
		tsp = flook(arg1, TRUE);
		return tsp == NULL ? "" : tsp;
	case UFBAND:
		return itoa(atoi(arg1) & atoi(arg2));
	case UFBOR:
		return itoa(atoi(arg1) | atoi(arg2));
	case UFBXOR:
		return itoa(atoi(arg1) ^ atoi(arg2));
	case UFBNOT:
		return itoa(~atoi(arg1));
	case UFXLATE:
		return xlat(arg1, arg2, arg3);
	}

	exit(-11);		/* never should get here */
}