Commit 5325a5b7 authored by Benoit Barbot's avatar Benoit Barbot

prog

parent 02492bdc
Pipeline #1056 passed with stages
in 16 minutes and 35 seconds
......@@ -20,7 +20,7 @@ OUTPUT_STRIP_TRAILING_WHITESPACE
)
ADD_DEFINITIONS(
-O3
-O3 -Wall -Wno-sign-compare
-DGIT_REVISION=\"${GIT_REVISION}\"
-DBOOST_PATH=\"-I${Boost_INCLUDE_DIRS}\"
-DBOOST_LIB=\"${Boost_LIBRARIES}\"
......@@ -191,7 +191,7 @@ SOURCES ${ml_SOURCES}
)
add_executable(testClientSim ${CMAKE_CURRENT_BINARY_DIR}/tmp/spn.cpp ${CMAKE_CURRENT_BINARY_DIR}/tmp/LHA.cpp)
target_compile_options(testClientSim PRIVATE -Wno-return-type)
target_compile_options(testClientSim PRIVATE -Wno-return-type -Wno-unused-variable -Wno-unused-but-set-variable)
include_directories("src/Simulator")
add_dependencies(testClientSim Cosmos)
target_link_libraries (testClientSim ClientSimMain ClientSimBase)
......
......@@ -367,7 +367,7 @@ void Gspn_Writer::writeTok(ostream &SpnF,const coloredToken &sct,const colorDoma
SpnF << ")";
}
if( !sct.mult.is_concrete() || sct.mult.intVal != 1) SpnF << " * (" << sct.mult<< ")";
}else SpnF << sct.mult ;
}
......@@ -398,7 +398,7 @@ void Gspn_Writer::writeTransition(ofstream & spnF)const{
}
if(!P.is_domain_impl_set){
spnF << "\t{ ";
spnF << "//"<< tr.name << "\n\tabstractBinding bl;" << endl;
spnF << "\tbl.idcount = static_cast<int>(Transition["<< tr.id <<"].bindingList.size());"<< endl;
bool atleastone = false;
......@@ -432,8 +432,8 @@ void Gspn_Writer::writeTransition(ofstream & spnF)const{
spnF << "\tTransition["<< tr.id <<"].bindingList.push_back( bl );\n\t}\n";
}
}
if (P.verbose > 7) {
spnF << "\tstd::cerr << \"\\n\\n\";\n";
}
......@@ -1071,7 +1071,7 @@ void Gspn_Writer::writeMarkingClasse(ofstream &SpnCppFile,ofstream &header)const
SpnCppFile << "P->"<< colvar.name << ".c0 + Color_"<< MyGspn.colDoms[colvar.type].name << "_Total *(";
}
SpnCppFile << "0";
for (let colvar : MyGspn.colVars) SpnCppFile << ")";
for (int i=0; i< MyGspn.colVars.size() ;i++) SpnCppFile << ")";
} else SpnCppFile << "0";
SpnCppFile << ";\n}\n";
}
......
......@@ -118,4 +118,3 @@ Unserializer Unserializer::operator&(std::string &d){
inf.read(&d[0], length);
return *this;
}
......@@ -166,7 +166,7 @@ struct parameters {
ModelType modelType;
LHAType lhaType;
std::string Path;
std::string PathGspn;
std::string PathLha;
......@@ -189,7 +189,7 @@ struct parameters {
bool GMLinput;
int computeStateSpace;
bool lumpStateSpace;
bool alligatorMode;
bool guiGreatSpnMode;
std::string unfold;
......@@ -217,13 +217,13 @@ struct parameters {
std::string magic_values;
bool use_magic_print;
bool is_domain_impl_set;
std::vector<HaslFormulasTop*> HaslFormulas;
std::vector<std::string> HaslFormulasname;
size_t nbAlgebraic;
size_t nbQualitatif;
size_t nbPlace;
parameters();
void View();
void usage();
......@@ -235,21 +235,21 @@ public:
void serialize(Archive & ar){
ar & verbose & interactive & seed & randomGen & Njob;
ar & epsilon & continuousStep & Level & Width & Batch & MaxRuns & sequential & relative & chernoff;
ar & comp_uuid & tmpPath & (int&)tmpStatus & reuse & graceFullEnding ;
ar & (int&)modelType & (int&)lhaType;
ar & Path & PathGspn & PathLha & constants;
ar & (int&)generateLHA & loopLHA & loopTransientLHA & CSLformula & externalHASL;
ar & localTesting & RareEvent & DoubleIS & BoundedRE & horizon & BoundedContinuous;
ar & CountTrans & StringInSpnLHA & GMLinput & computeStateSpace & lumpStateSpace;
ar & prismPath & dataoutput & dataraw & datatrace & sampleResol & dataPDFCDF & gnuplotDriver;
ar & tracedPlace & dotfile & magic_values & use_magic_print & is_domain_impl_set;
}
};
/**
......
......@@ -43,12 +43,12 @@ void generateEvent(double ctime,Event& E,size_t Id,const abstractBinding& b, tim
if (N.Transition[Id].DistTypeIndex != IMMEDIATE) {
N.getParams(Id, b);
t += TG.GenerateTime(N.Transition[Id].DistTypeIndex, Id, N.ParamDistr, N.customDistr);
N.Rate_Table[Id] = N.ParamDistr[0];
N.Origine_Rate_Table[Id] = N.ParamDistr[1];
N.Rate_Sum = N.Rate_Sum + N.ParamDistr[0];
N.Origine_Rate_Sum = N.Origine_Rate_Sum + N.ParamDistr[1];
}
double w=0.0;
if (N.Transition[Id].DistTypeIndex > 2) {
......@@ -57,13 +57,13 @@ void generateEvent(double ctime,Event& E,size_t Id,const abstractBinding& b, tim
//vector<double> wParam(1, N.GetWeight(Id));
//w = GenerateTime(2, wParam);
}
E.transition = Id;
E.time = t;
E.priority = N.GetPriority(Id,b);
E.weight = w;
E.binding = b;
}
......@@ -93,94 +93,94 @@ void SimulatorREBase<S, DEDS>::initVect(){
template<class S>
void SPNBaseRE<S>::InitialEventsQueue(EventsQueue &EQ,timeGen &TG) {
Rate_Sum = 0;
Origine_Rate_Sum = 0;
SPNBase<S,EventsQueue>::initialEventsQueue(EQ,TG);
Rate_Sum = 0;
Origine_Rate_Sum = 0;
SPNBase<S,EventsQueue>::initialEventsQueue(EQ,TG);
}
template <class S, class DEDS>
void SimulatorREBase<S, DEDS>::returnResultTrue(){
this->A.getFinalValues(
this->A.getFinalValues(
this->N.getState(),
this->Result.quantR,
this->Result.qualR);
this->Result.accept = true;
this->Result.accept = true;
for(size_t i = 0; i< this->A.FormulaVal.size() ; i++)
this->Result.quantR[i] *= this->A.Likelihood;
if(P.verbose>3)cerr << "---------------\n TRUE: Likelyhood: "<< this->A.Likelihood <<" \n------\n";
if(P.verbose>3)cerr << "---------------\n TRUE: Likelyhood: "<< this->A.Likelihood <<" \n------\n";
}
template <class S>
void SPNBaseRE<S>::update(double ctime,size_t t, const abstractBinding& b,EventsQueue &EQ,timeGen &TG){
//If rareevent not require yet call the parent function
if(!rareEventEnabled){
if(precondition(this->Marking)){
rareEventEnabled = true;
//A.Likelihood = 1.0;
}else{
SPNBase<S,EventsQueue>::update(ctime, t, b,EQ, TG);
return;
}
}
Event F;
Rate_Sum = 0;
Origine_Rate_Sum = 0;
//Run over all transitions
for (const auto &tr : this->Transition) {
//If rareevent not require yet call the parent function
if(!rareEventEnabled){
if(precondition(this->Marking)){
rareEventEnabled = true;
//A.Likelihood = 1.0;
}else{
SPNBase<S,EventsQueue>::update(ctime, t, b,EQ, TG);
return;
}
}
Event F;
Rate_Sum = 0;
Origine_Rate_Sum = 0;
//Run over all transitions
for (const auto &tr : this->Transition) {
if(tr.Id != this->tr - 1){
for(const auto &bindex : tr.bindingList ){
if(this->IsEnabled(tr.Id, bindex)){
if (EQ.isScheduled(tr.Id, bindex.id())) {
generateEvent(ctime,F, tr.Id ,bindex, TG, *this );
EQ.replace(F);
} else {
generateEvent(ctime,F, tr.Id ,bindex, TG, *this );
EQ.insert(F);
}
}else{
if(EQ.isScheduled(tr.Id, bindex.id()))
EQ.remove(tr.Id,bindex.id());
}
}
}
}
abstractBinding bpuit;
generateEvent(ctime,F, (this->tr-1), bpuit,TG, *this);
if(!doubleIS_mode){
EQ.replace(F);
}
/*
//In Debug mode check that transition are scheduled iff they are enabled
for (const auto &tr : N.Transition) {
for(const auto &bindex : tr.bindingList){
if (N.IsEnabled(tr.Id, bindex) !=
EQ->isScheduled(tr.Id, bindex.id())){
cerr << "N.IsEnabled(" << tr.label << ",";
bindex.print();
cerr <<")" << endl;
if(EQ->isScheduled(tr.Id, bindex.id())){
cerr << "Scheduled and not enabled!"<< endl;
}else{
cerr << "Enabled and not scheduled!" << endl;
}
assert(N.IsEnabled(tr.Id, bindex) ==
EQ->isScheduled(tr.Id, bindex.id()));
}
}
}
*/
for(const auto &bindex : tr.bindingList ){
if(this->IsEnabled(tr.Id, bindex)){
if (EQ.isScheduled(tr.Id, bindex.id())) {
generateEvent(ctime,F, tr.Id ,bindex, TG, *this );
EQ.replace(F);
} else {
generateEvent(ctime,F, tr.Id ,bindex, TG, *this );
EQ.insert(F);
}
}else{
if(EQ.isScheduled(tr.Id, bindex.id()))
EQ.remove(tr.Id,bindex.id());
}
}
}
}
abstractBinding bpuit;
generateEvent(ctime,F, (this->tr-1), bpuit,TG, *this);
if(!doubleIS_mode){
EQ.replace(F);
}
/*
//In Debug mode check that transition are scheduled iff they are enabled
for (const auto &tr : N.Transition) {
for(const auto &bindex : tr.bindingList){
if (N.IsEnabled(tr.Id, bindex) !=
EQ->isScheduled(tr.Id, bindex.id())){
cerr << "N.IsEnabled(" << tr.label << ",";
bindex.print();
cerr <<")" << endl;
if(EQ->isScheduled(tr.Id, bindex.id())){
cerr << "Scheduled and not enabled!"<< endl;
}else{
cerr << "Enabled and not scheduled!" << endl;
}
assert(N.IsEnabled(tr.Id, bindex) ==
EQ->isScheduled(tr.Id, bindex.id()));
}
}
}
*/
};
template<class S, class DEDS>
void SimulatorREBase<S, DEDS>::updateLikelihood(size_t E1_transitionNum){
if(P.verbose>4){
cerr << "initialised?:\t" << E1_transitionNum << "\t" << this->A.Likelihood << endl;
cerr << this->N.Rate_Sum << "\t" << this->N.Origine_Rate_Sum << "\t[";
......@@ -189,18 +189,18 @@ void SimulatorREBase<S, DEDS>::updateLikelihood(size_t E1_transitionNum){
for(let cv:this->N.Origine_Rate_Table)cerr << cv << ", ";
cerr << "]" << endl;
}
if(this->N.doubleIS_mode){
this->A.Likelihood = this->A.Likelihood *
(this->N.Origine_Rate_Table[E1_transitionNum] / this->N.Origine_Rate_Sum) *
((this->N.Rate_Sum-this->N.Rate_Table[this->N.tr-1]) / this->N.Rate_Table[E1_transitionNum]);
}else{
this->A.Likelihood = this->A.Likelihood *
//
//(N.Origine_Rate_Table[E1_transitionNum] / 1.0) *
(this->N.Origine_Rate_Table[E1_transitionNum] / this->N.Origine_Rate_Sum) *
(this->N.Rate_Sum / this->N.Rate_Table[E1_transitionNum]);
}
if(this->N.doubleIS_mode){
this->A.Likelihood = this->A.Likelihood *
(this->N.Origine_Rate_Table[E1_transitionNum] / this->N.Origine_Rate_Sum) *
((this->N.Rate_Sum-this->N.Rate_Table[this->N.tr-1]) / this->N.Rate_Table[E1_transitionNum]);
}else{
this->A.Likelihood = this->A.Likelihood *
//
//(N.Origine_Rate_Table[E1_transitionNum] / 1.0) *
(this->N.Origine_Rate_Table[E1_transitionNum] / this->N.Origine_Rate_Sum) *
(this->N.Rate_Sum / this->N.Rate_Table[E1_transitionNum]);
}
}
template<class S, class DEDS>
......@@ -230,59 +230,59 @@ void SimulatorREBase<S, DEDS>::reset(){
*/
template<class S, class DEDS>
void SimulatorREBase<S, DEDS>::SimulateSinglePath() {
this->N.rareEventEnabled = this->N.precondition(this->N.getState());
this->N.rareEventEnabled = this->N.precondition(this->N.getState());
static_cast<S*>(this)->reset();
this->N.InitialEventsQueue(*(this->EQ),*this);
if(this->logtrace.is_open())this->logtrace << "New Path"<< endl;
bool continueb = true;
while ((!this->EQ->isEmpty()) && continueb ) {
if(this->logtrace.is_open())this->logtrace << "New Path"<< endl;
bool continueb = true;
while ((!this->EQ->isEmpty()) && continueb ) {
//cerr << "continue path"<< endl;
if(this->logtrace.is_open()){
this->logtrace << this->A.CurrentTime << "\t";
this->N.getState().print(this->logtrace,0.0);
this->A.printState(this->logtrace);
this->logtrace << endl;
}
if(P.verbose>3){
//Print marking and location of the automata
//Usefull to track a simulation
this->N.getState().printHeader(cerr);
this->A.printHeader(cerr);
cerr << endl;
this->N.getState().print(cerr,0.0);
this->A.printState(cerr);
if(this->logtrace.is_open()){
this->logtrace << this->A.CurrentTime << "\t";
this->N.getState().print(this->logtrace,0.0);
this->A.printState(this->logtrace);
this->logtrace << endl;
}
if(P.verbose>3){
//Print marking and location of the automata
//Usefull to track a simulation
this->N.getState().printHeader(cerr);
this->A.printHeader(cerr);
cerr << endl;
this->N.getState().print(cerr,0.0);
this->A.printState(cerr);
cerr << "\t" << this->A.Likelihood;
cerr << endl;
if(P.verbose>4)this->EQ->view(this->N.getTransitionLabels());
if(P.verbose==6)this->interactiveSimulation();
}
continueb = static_cast<S*>(this)->SimulateOneStep();
if(!this->N.rareEventEnabled)this->N.rareEventEnabled = this->N.precondition(this->N.getState());
}
cerr << endl;
if(P.verbose>4)this->EQ->view(this->N.getTransitionLabels());
if(P.verbose==6)this->interactiveSimulation();
}
continueb = static_cast<S*>(this)->SimulateOneStep();
if(!this->N.rareEventEnabled)this->N.rareEventEnabled = this->N.precondition(this->N.getState());
}
//cerr << "finish path"<< endl;
}
template <class S>
void SPNBaseRE<S>::getParams(size_t Id,const abstractBinding& b){
//If rareevent not require yet call the parent function
if(!rareEventEnabled){
//If rareevent not require yet call the parent function
if(!rareEventEnabled){
this->GetDistParameters(Id,b);
return;
}
this->GetDistParameters(Id,b);
this->ParamDistr[1]= this->ParamDistr[0];
this->ParamDistr[0]= ComputeDistr( Id, b, this->ParamDistr[0]);
return;
}
this->GetDistParameters(Id,b);
this->ParamDistr[1]= this->ParamDistr[0];
this->ParamDistr[0]= ComputeDistr( Id, b, this->ParamDistr[0]);
//N.ParamDistr[0]= N.ParamDistr[1]; /////////////////////////////////////////////////to remove
}
template <class S>
double SPNBaseRE<S>::mu(){
vector<int> vect (muprob->S.begin()->first->size(),0);
vector<int> vect (muprob->S.begin()->first->size(),0);
lumpingFun(this->Marking,vect);
//cerr << "test(";
int i = muprob->findHash(&vect);
......@@ -292,41 +292,40 @@ double SPNBaseRE<S>::mu(){
cerr << vect[j] << ",";
}
cerr << ") ->" << i << endl;
this->Marking.printHeader(cerr);
cerr << endl;
this->Marking.print(cerr,0.0);
cerr << endl;
print_state(vect);
this->Marking.printHeader(cerr);
cerr << endl;
this->Marking.print(cerr,0.0);
cerr << endl;
print_state(vect);
if(i<0)exit(EXIT_FAILURE);
}
if(P.verbose>3)cerr << "muValue: " << muprob->getMu(i) << endl;
return muprob->getMu(i);
if(P.verbose>3)cerr << "muValue: " << muprob->getMu(i) << endl;
return muprob->getMu(i);
}
template <class S>
double SPNBaseRE<S>::ComputeDistr(size_t t , const abstractBinding& b, double origin_rate){
if(P.verbose>4)cerr << "trans: " << this->Transition[t].label << " mu origine:";
double mux = mu();
if( mux==0.0 || mux==1.0) return(origin_rate);
if(t== this->tr-1){
if(Origine_Rate_Sum >= Rate_Sum){
return( Origine_Rate_Sum - Rate_Sum );
}else{
if(P.verbose>3 && (Origine_Rate_Sum < 0.99*Rate_Sum)){
cerr << "Reduce model does not guarantee variance" << endl;
cerr << "Initial sum of rate: " << Origine_Rate_Sum << " Reduce one: " << Rate_Sum << " difference: " << Origine_Rate_Sum - Rate_Sum << endl ;
//exit(EXIT_FAILURE);
}
return 0.0 ;};
};
if(P.verbose>4)cerr << "mu target : ";
double distr;
this->fire(t,b,0.0);
distr = origin_rate *( mu() / mux);
this->unfire(t,b);
if(P.verbose>4)cerr <<endl;
return(distr);
}
if(P.verbose>4)cerr << "trans: " << this->Transition[t].label << " mu origine:";
double mux = mu();
if( mux==0.0 || mux==1.0) return(origin_rate);
if(t== this->tr-1){
if(Origine_Rate_Sum >= Rate_Sum){
return( Origine_Rate_Sum - Rate_Sum );
}else{
if(P.verbose>3 && (Origine_Rate_Sum < 0.99*Rate_Sum)){
cerr << "Reduce model does not guarantee variance" << endl;
cerr << "Initial sum of rate: " << Origine_Rate_Sum << " Reduce one: " << Rate_Sum << " difference: " << Origine_Rate_Sum - Rate_Sum << endl ;
//exit(EXIT_FAILURE);
}
return 0.0 ;};
};
if(P.verbose>4)cerr << "mu target : ";
double distr;
this->fire(t,b,0.0);
distr = origin_rate *( mu() / mux);
this->unfire(t,b);
if(P.verbose>4)cerr <<endl;
return(distr);
}
......@@ -47,7 +47,7 @@ template <class F>
double boost_newton_raphson_iterate(F f, double guess, double min, double max, int max_iter)
{
int digits = 16;
double f0(0), f1, last_f0(0);
double f0(0), f1;
double result = guess;
double factor = static_cast<double>(ldexp(1.0, 1 - digits));
......@@ -58,7 +58,6 @@ double boost_newton_raphson_iterate(F f, double guess, double min, double max, i
unsigned int count(max_iter);
do{
last_f0 = f0;
delta2 = delta1;
delta1 = delta;
std::tie(f0, f1) = f(result);
......@@ -426,7 +425,7 @@ double timeGen::GenerateTime(DistributionType distribution,size_t trid, const ar
double lower = cd.userDefineLowerBound(param);
double upper = cd.userDefineUpperBound(param);
/*//Isotrop Hack
std::uniform_real_distribution<> unif(lower, upper);
gentime = unif(RandomNumber);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment