コード例 #1
0
ファイル: PetriNetBuilder.cpp プロジェクト: jonasfj/PeTe
PetriNet* PetriNetBuilder::makePetriNet(){
	PetriNet* net = new PetriNet(places.size(), transitions.size(), variables.size());
	size_t i;
	//Create variables
	for(i = 0; i < variables.size(); i++){
		net->_variables[i] = variables[i];
		net->_ranges[i] = ranges[i];
	}
	//Create place names
	for(i = 0; i < places.size(); i++)
		net->_places[i] = places[i];
	//Create transition names
	for(i = 0; i < transitions.size(); i++)
		net->_transitions[i] = transitions[i];
	//Parse conditions and assignments
	for(i = 0; i < transitions.size(); i++){
		if(conditions[i] != ""){
			net->_conditions[i] = PQL::ParseQuery(conditions[i]);
			if(net->_conditions[i]){
				PQL::AnalysisContext context(*net);
				if(_jit){
					PQL::CompiledCondition* CC = new PQL::CompiledCondition(net->_conditions[i]);
					CC->analyze(context);
					if(CC->compile())
						net->_conditions[i] = CC;
					else{
						delete CC;
						CC = NULL;
						//TODO: Print to stderr
					}
				}else
					net->_conditions[i]->analyze(context);

				//Delete if there we're errors
				if(context.errors().size() > 0){
					delete net->_conditions[i];
					net->_conditions[i] = NULL;
					//TODO: Print to stderr
				}
			}
		}
		if(assignments[i] != ""){
			net->_assignments[i] = PQL::ParseAssignment(assignments[i]);
			if(net->_assignments[i]){
				PQL::AnalysisContext context(*net);
				net->_assignments[i]->analyze(context);
				//Delete if there we're errors
				if(context.errors().size() > 0){
					delete net->_assignments[i];
					net->_assignments[i] = NULL;
					//TODO: Print to stderr
				}
			}
		}
	}
	//Create input arcs
	vector<Arc>::iterator arc;
	for(arc = inputArcs.begin(); arc != inputArcs.end(); arc++){
		int place = -1, transition = -1;
		//Find place number
		for(i = 0; i < places.size(); i++){
			if(places[i] == arc->place){
				place = i;
				break;
			}
		}
		//Find transition number
		for(i = 0; i < transitions.size(); i++){
			if(transitions[i] == arc->transition){
				transition = i;
				break;
			}
		}
		//We should have found a places and transition
		assert(place >= 0 && transition >= 0);
		net->_tv(transition)[place] = arc->weight;
	}
	//Create output arcs
	for(arc = outputArcs.begin(); arc != outputArcs.end(); arc++){
		int place = -1, transition = -1;
		//Find place number
		for(i = 0; i < places.size(); i++){
			if(places[i] == arc->place){
				place = i;
				break;
			}
		}
		//Find transition number
		for(i = 0; i < transitions.size(); i++){
			if(transitions[i] == arc->transition){
				transition = i;
				break;
			}
		}
		//We should have found a places and transition
		assert(place >= 0 && transition >= 0);
		net->_tv(transition)[place + places.size()] = arc->weight;
	}
	//Return the finished net
	return net;
}