int main(){ cout<<"Allocating memory"<<endl; state** s = setUpStates(); vector<transition*> t; testSet ts, *prioSet=0, *extendSet=0, *multiextendSet=0; if(!clearWD()){ cerr<<"Error preping up WD\n"; return 1; } setUpTransitions(&t,s); printHeader("Traffic Lights FSM",OUT); printFml(s,&t,OUT); wrapUp(OUT); parseSpecs(s,&t,"specs",&ts); vector<transitionPair*> *tp=getTPairs(s,&t); cout<<"Test cases parsed.\nSelect operation to perform:\n"; cout<<"\t1 - Generate diagrams for the original test set\n"; cout<<"\t2 - Generate diagrams for the minimized test set using Priority Cull\n"; cout<<"\t3 - Generate diagrams for the minimized test set using Subgraph Cull\n"; cout<<"\t4 - Generate diagrams for the minimized test set using Multi-Stage Subgraph Cull\n"; cout<<"\t9 - Perform Stress Test\n"; cout<<"\t0 - Exit application\n"; cout<<"---------------------------------------------\n"; int option=0; cin>>option; float tpc=0; bool *selectedTestCases=0; int MAX_TESTS=0; switch(option){ case 1: ts.printTestSet(s,&t); cout<<"Test set size: "<<ts.getSize()<<endl; tpc=ts.computeTPairCoverage(tp); cout<<"Transition-Pair Coverage: "<<tpc*100<<"%"<<endl; selectedTestCases=ts.getSelectedCases(ts.getSize()); createScript(selectedTestCases, ts.getSize(), string(SCRIPT)); cout<<"---------------------------------------------\nJob Done.\n"; break; case 2: prioSet=ts.priorityCull(tp); prioSet->printTestSet(s,&t); cout<<"Original Test set size: "<<ts.getSize()<<endl; cout<<"Final Test set size: "<<prioSet->getSize()<<endl; tpc=prioSet->computeTPairCoverage(tp); cout<<"Transition-Pair Coverage: "<<tpc*100<<"%"<<endl; selectedTestCases=prioSet->getSelectedCases(ts.getSize()); createScript(selectedTestCases, ts.getSize(), string(SCRIPT)); cout<<"---------------------------------------------\nJob Done.\n"; break; case 3: extendSet=ts.subgraphCull(tp,s); extendSet->printTestSet(s,&t); cout<<"Original Test set size: "<<ts.getSize()<<endl; cout<<"Final Test set size: "<<extendSet->getSize()<<endl; tpc=extendSet->computeTPairCoverage(tp); cout<<"Transition-Pair Coverage: "<<tpc*100<<"%"<<endl; selectedTestCases=extendSet->getSelectedCases(ts.getSize()); createScript(selectedTestCases, ts.getSize(), string(SCRIPT)); cout<<"---------------------------------------------\nJob Done.\n"; break; case 4: multiextendSet=ts.multiStageSubgraphCull(tp,s); multiextendSet->printTestSet(s,&t); cout<<"Original Test set size: "<<ts.getSize()<<endl; cout<<"Final Test set size: "<<multiextendSet->getSize()<<endl; tpc=multiextendSet->computeTPairCoverage(tp); cout<<"Transition-Pair Coverage: "<<tpc*100<<"%"<<endl; selectedTestCases=multiextendSet->getSelectedCases(ts.getSize()); createScript(selectedTestCases, ts.getSize(), string(SCRIPT)); cout<<"---------------------------------------------\nJob Done.\n"; break; case 9: cout<<"Enter number of test cases: "; cin>>MAX_TESTS; stressTest(MAX_TESTS,10,tp,s); break; default: break; } cout<<"Freeing memory.."<<endl; tp->clear(); if(prioSet) delete prioSet; if(extendSet) delete extendSet; if(selectedTestCases) delete [] selectedTestCases; dropStates(s); cout<<"Exiting application.\n"; system("pause"); return 0; }
// ------------------------------------------------------------------------------- // The support routines // ------------------------------------------------------------------------------- /// Add states to the filter, called just before the MU /// Return the number of states added and dropped. virtual int KalmanAddsDrops(int which, double T) throw(gpstk::Exception) { try { gpstk::SRI addsSRI, dropSRI; gpstk::Namelist addsNL; // get new adds and drops from the caller int iret = defineAddsDrops(which, T, addsSRI, dropsNL); if(iret < 0) return 0; // skip this epoch iret = 0; // drop states that were found in the last iteration if(dropsNL.size() > 0) { LOG(DEBUG) << "KalmanAddsDrops(" << which << ") drops " << dropsNL; gpstk::Namelist saveNL(srif.getNames()); // get state without inverting information matrix int i,k,nsingular; gpstk::Vector<double> X; try { srif.getState(X, &nsingular); } catch(gpstk::MatrixException& me) { for(k=0; k<dropsNL.size(); k++) { i = saveNL.index(dropsNL.getName(k)); if(nsingular == -1 || i < nsingular) { gpstk::Exception e("Cannot drop states; problem is singular"); GPSTK_THROW(e); } } } //LOG(INFO) << "SRIF before drops:\n" << std::fixed // << std::setprecision(5) << std::setw(10) << srif; //LOG(INFO) << "State before drops:\n" << std::fixed // << std::setprecision(5) << std::setw(10) << X; // fill a vector of drop states gpstk::Vector<double> dropStates(dropsNL.size()); for(k=0; k<dropsNL.size(); k++) { i = saveNL.index(dropsNL.getName(k)); dropStates(k) = X(i); } //LOG(DEBUG) << "Drops states are " << std::fixed << std::setprecision(5) // << std::setw(10) << dropStates; srif.stateFix(dropsNL, dropStates); //LOG(DEBUG) << "srif after drops:\n" << std::scientific // << std::setprecision(5) << std::setw(10) << srif; iret += dropsNL.size(); } if(addsSRI.size() > 0) { LOG(DEBUG) << "KalmanAddsDrops(" << which << ") adds " << addsSRI.getNames(); // check that addsNL and srif have no states in common if((addsNL & srif.getNames()).size() > 0) { gpstk::Exception e("Adding a state that is already present"); GPSTK_THROW(e); } //LOG(DEBUG) << "srif before adds:\n" << std::fixed // << std::setprecision(5) << std::setw(10) << srif; // append addsSRI onto end srif.append(addsSRI); iret += addsSRI.size(); //LOG(DEBUG) << "srif after adds:\n" << std::fixed // << std::setprecision(5) << std::setw(10) << srif; } return iret; } catch(gpstk::Exception& e) { e.addText("KADD"); GPSTK_RETHROW(e); } }