Commit 28c99a9b authored by pitiot's avatar pitiot

stats

parent 59ec48c3
......@@ -16,6 +16,8 @@
#include <fstream>
#include <sstream>
timespec timespec_delta(const timespec& t1, const timespec& t2);
class ThreadUpdateInfo
{
public:
......@@ -145,6 +147,8 @@ public:
long int time_agent;
long int time_obstacle;
long int time_behave;
long int time_multires;
};
#endif
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include <iostream>
#include <fstream>
#include <sys/time.h>
#include "Utils/Qt/qtSimple.h"
......@@ -156,7 +157,8 @@ public:
static const float RADIUS = 3950.0f;
Utils::GLSLShader m_DeferedShader;
Utils::GLSLShader m_DeferedShader2;
std::stringstream filename;
std::stringstream name;
enum renderMode {SIMPLE} ;
int m_renderStyle;
......@@ -211,13 +213,14 @@ public:
int posXSlider;
int posYSlider;
bool display_times;
bool percent;
public slots:
void animate() ;
void slot_timer(bool b)
{
b ? timer->start() : timer->stop() ;
clock_gettime(CLOCK_MONOTONIC, &startTime) ;
// display_times =b;
}
void slot_drawEnvLines(bool b)
......
......@@ -80,8 +80,8 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
CityGenerator::generateCity<PFP>(*this,0) ;
break ;
case 1 :
// CityGenerator::generateGrid<PFP>(*this) ;
CityGenerator::generateTrianGrid<PFP>(*this,obstacleMark, buildingMark);
CityGenerator::generateGrid<PFP>(*this) ;
// CityGenerator::generateTrianGrid<PFP>(*this,obstacleMark, buildingMark);
break ;
case 2 :
CityGenerator::generateGrid<PFP>(*this) ;
......
#include "simulator.h"
#include "env_generator.h"
timespec timespec_delta(const timespec& t1, const timespec& t2) {
timespec result;
if ((t2.tv_nsec - t1.tv_nsec) < 0 /* ns */) {
result.tv_sec = t2.tv_sec - t1.tv_sec - 1;
result.tv_nsec = 1000000000 /* ns */ + t2.tv_nsec - t1.tv_nsec;
} else {
result.tv_sec = t2.tv_sec - t1.tv_sec;
result.tv_nsec = t2.tv_nsec - t1.tv_nsec;
}
return result;
}
Simulator::Simulator(unsigned int config, unsigned int minS, unsigned int nbAgent, unsigned int nbObst, bool resolution) :
timeStep_(0.05f),
......@@ -16,7 +29,9 @@ Simulator::Simulator(unsigned int config, unsigned int minS, unsigned int nbAgen
avoidance(1),
nb_dead(0),
time_agent(0),
time_obstacle(0)
time_obstacle(0),
time_behave(0),
time_multires(0)
{
minSize=minS;
multires=resolution;
......@@ -107,31 +122,34 @@ void Simulator::doStep()
envMap_.clearUpdateCandidates() ;
envMap_.map.setCurrentLevel(envMap_.map.getMaxLevel()) ;
#endif
unsigned long begTime, endTime;
begTime=clock() ;
struct timespec begTime, endTime ;
for (unsigned int i = 0 ; i < movingObstacles_.size() ; ++i)
{
clock_gettime(CLOCK_MONOTONIC, &begTime) ;
movingObstacles_[i]->computePrefVelocity() ;
movingObstacles_[i]->computeNewVelocity() ;
clock_gettime(CLOCK_MONOTONIC, &endTime) ;
time_behave+= timespec_delta(begTime,endTime).tv_nsec;
clock_gettime(CLOCK_MONOTONIC, &begTime) ;
movingObstacles_[i]->updateAgentNeighbors();
movingObstacles_[i]->updateObstacleNeighbors();
#ifndef SPATIAL_HASHING
envMap_.map.setCurrentLevel(envMap_.map.getMaxLevel()) ;
#endif
movingObstacles_[i]->update() ;
clock_gettime(CLOCK_MONOTONIC, &endTime) ;
time_obstacle+= timespec_delta(begTime,endTime).tv_nsec;
// commente par Arash
movingObstacles_[i]->updateMesh() ;
}
endTime=clock() ;
time_obstacle+= endTime-begTime;
begTime=clock() ;
for (unsigned int i = 0 ; i < agents_.size() ; ++i)
{
if (agents_[i]->alive)
{
clock_gettime(CLOCK_MONOTONIC, &begTime) ;
agents_[i]->updateObstacleNeighbors() ;
#ifndef SPATIAL_HASHING
......@@ -141,9 +159,13 @@ void Simulator::doStep()
#ifndef SPATIAL_HASHING
envMap_.map.setCurrentLevel(0) ;
#endif
clock_gettime(CLOCK_MONOTONIC, &endTime) ;
time_agent+=timespec_delta(begTime,endTime).tv_nsec;
clock_gettime(CLOCK_MONOTONIC, &begTime) ;
agents_[i]->computePrefVelocity() ;
agents_[i]->computeNewVelocity() ;
clock_gettime(CLOCK_MONOTONIC, &endTime) ;
time_behave+=timespec_delta(begTime,endTime).tv_nsec;
}
}
......@@ -163,6 +185,7 @@ void Simulator::doStep()
if (multires)
envMap_.map.setCurrentLevel(envMap_.map.getMaxLevel()) ;
nb_dead = 0 ;
clock_gettime(CLOCK_MONOTONIC, &begTime) ;
for (unsigned int i = 0 ; i < agents_.size() ; ++i)
{
if (agents_[i]->alive)
......@@ -186,14 +209,19 @@ void Simulator::doStep()
nb_dead++ ;
}
endTime=clock() ;
time_agent+= endTime-begTime;
clock_gettime(CLOCK_MONOTONIC, &endTime) ;
time_agent+= timespec_delta(begTime,endTime).tv_nsec;
nbRefineCandidate += envMap_.refineCandidate.size() ;
nbCoarsenCandidate += envMap_.coarsenCandidate.size() ;
if (multires)
{
clock_gettime(CLOCK_MONOTONIC, &begTime) ;
envMap_.updateMap() ;
clock_gettime(CLOCK_MONOTONIC, &endTime) ;
time_multires+= timespec_delta(begTime,endTime).tv_nsec;
}
#endif
globalTime_ += timeStep_ ;
......@@ -229,7 +257,8 @@ void Simulator::setupCircleScenario(unsigned int nbAgents , unsigned int nbObsta
else
{
envMap_.init(config, 2000.0f, 2000.0f, minSize, 400.0f) ; //cases fines
// envMap_.init(config, 2000.0f, 2000.0f, minSize, 50.0f) ; //cases fines
envMap_.init(config, 2000.0f, 2000.0f, minSize, 400.0f) ; //grosses cases
}
std::cout << " - Setup Circle Scenario : " << nbAgents << " agents et " << nbObstacles << " obstacles"<< std::endl ;
......@@ -355,7 +384,8 @@ void Simulator::setupCorridorScenario(unsigned int nbAgents, unsigned int nbObst
else
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 320.0f) ; //cases fines
// envMap_.init(config, 1600.0f, 960.0f, minSize, 320.0f) ; //grosses cases
envMap_.init(config, 1600.0f, 960.0f, 40.0f, 40.0f) ; //cases fines
}
......
......@@ -60,6 +60,18 @@ SocialAgents::SocialAgents(unsigned int config, unsigned int minSize, unsigned i
display_times(false)
{
timer = new QTimer(this) ;
switch (config){
case 0 :name<<"cercle_";break;
case 1 :name<<"corridor_";break;
case 2 :name<<"corridorSnake_";break;
case 3 :name<<"ville_";break;
case 5 :name<<"strasbourg_";break;
default : break;
}
filename<<name.str().c_str()<<nbAgent<<"_"<<nbObst<<"_"<<resolution;
percent = false;
time_update = 0 ;
elapsedTime = 0;
connect(timer, SIGNAL(timeout()), this, SLOT(animate())) ;
......@@ -850,21 +862,22 @@ void SocialAgents::cb_redraw()
++frames ;
struct timespec realTime ;
clock_gettime(CLOCK_MONOTONIC, &realTime) ;
elapsedTime += realTime.tv_sec - startTime.tv_sec ;
elapsedTime += timespec_delta(startTime,realTime).tv_nsec ;
clock_gettime(CLOCK_MONOTONIC, &startTime) ;
if(display_times)
{
CGoGNout <<CGoGNendl;
CGoGNout << "temps mis pour "<<nbIterations<< " : "<< elapsedTime<<CGoGNendl;
CGoGNout << "temps mis pour l'affichage : "<< (float)elapsedTime - (((float)time_update)/CLOCKS_PER_SEC)<<CGoGNendl;
CGoGNout << "temps mis pour le DoStep : "<< (((float)time_update)/CLOCKS_PER_SEC)<<CGoGNendl;
CGoGNout << "temps mis pour les Agents : "<< (((float) simulator.time_agent)/CLOCKS_PER_SEC)<<CGoGNendl;
CGoGNout << "temps mis pour les Agents Polygonaux : "<< (((float)simulator.time_obstacle)/CLOCKS_PER_SEC)<<CGoGNendl;
CGoGNout << "temps mis pour la multirésolution : "<<(((float)time_update)/CLOCKS_PER_SEC) - (((float) simulator.time_agent)/CLOCKS_PER_SEC) - (((float)simulator.time_obstacle)/CLOCKS_PER_SEC)<<CGoGNendl;
CGoGNout << "temps mis pour "<<nbIterations<< " : "<< elapsedTime/10000000.0f<<CGoGNendl;
CGoGNout << "temps mis pour l'affichage : "<< (long int)elapsedTime/10000000.0f - ((time_update)/1000000000.0f)<<CGoGNendl;
CGoGNout << "temps mis pour le DoStep : "<< ((time_update)/10000000.0f)<<CGoGNendl;
CGoGNout << "temps mis pour les Agents : "<< (( simulator.time_agent)/10000000.0f)<<CGoGNendl;
CGoGNout << "temps mis pour les Agents Polygonaux : "<< ((simulator.time_obstacle)/10000000.0f)<<CGoGNendl;
CGoGNout << "temps mis pour le Comportement : "<< ((simulator.time_behave)/10000000.0f)<<CGoGNendl;
CGoGNout << "temps mis pour la multirésolution : "<<((simulator.time_multires)/10000000.0f)<<CGoGNendl;
CGoGNout <<CGoGNendl;
display_times= false;
}
if (elapsedTime >= nextUpdate)
if (elapsedTime/1000000000.0f >= nextUpdate)
{
// Sortie des stats pour analyse externe
// std::cout << elapsedTime << ";" << frames << ";" << sim.nbUpdates << ";"
......@@ -873,7 +886,7 @@ void SocialAgents::cb_redraw()
// Affichage des stats dans la barre d'état
std::ostringstream oss ;
oss << "Elapsed time : " << elapsedTime ;
oss << "Elapsed time : " << elapsedTime/1000000000;
oss << " | " << frames << " fps" ;
oss << " | Iterations " << nbIterations ;
oss << " | Neighbors " << simulator.totalNeighbors
......@@ -898,7 +911,7 @@ void SocialAgents::cb_redraw()
simulator.nbRefineCandidate = 0 ;
simulator.nbCoarsenCandidate = 0 ;
frames = 0 ;
nextUpdate = elapsedTime + 1 ;
nextUpdate = elapsedTime/1000000000.0f + 1 ;
}
......@@ -1022,13 +1035,94 @@ void SocialAgents::animate()
{
// std::cout << "t : " << simulator.globalTime_ << std::endl ;
timer->stop() ;
if (filename != NULL)
{
if (percent) filename<<"_percent";
std::stringstream datas;
datas<<"stats/"<<filename.str().c_str()<<".dat";
std::stringstream gnuplots;
gnuplots<<"stats/"<<filename.str().c_str()<<".plt";
string data = datas.str();
string gnuplot=gnuplots.str();
float upAgent=((simulator.time_agent)/1000000000.0f);
float upObst = ((simulator.time_obstacle)/1000000000.0f);
float behaviour = ((simulator.time_behave)/1000000000.0f);
float rendu = 0/*(float)elapsedTime - (((float)time_update)/CLOCKS_PER_SEC)*/ ;
float multi = ((simulator.time_multires)/1000000000.0f);;
float sum = multi +upAgent+upObst+behaviour+rendu;
if(percent)
{
multi = (multi/sum)*100;
upAgent=(upAgent/sum)*100;
upObst = (upObst/sum)*100;
behaviour = (behaviour/sum)*100;
rendu =(rendu/sum)*100;
}
CGoGNout<<"temps total : "<<(time_update/1000000000.0f)<< CGoGNendl;
ofstream fichier(data.c_str(), ios::out | ios::trunc); //déclaration du flux et ouverture du fichier
if(fichier) // si l'ouverture a réussi
{
// instructions
fichier<<"#Multires\tMaJ des agents\tMaJ des obstacles\tComportement\tRendu"<<endl;
fichier<<0<<" "<<multi<<" "<<upAgent<<" "<<upObst<<" "<<behaviour<<" "<<rendu<<endl;
fichier.close();
}
else // sinon
{
cerr << "Erreur à l'ouverture !" << endl;
}
ofstream plot(gnuplot.c_str(), ios::out | ios::trunc); //déclaration du flux et ouverture du fichier
if(plot) // si l'ouverture a réussi
{
plot<<"set title '"<<maxIterations<<" itérations scénario "<<name.str().c_str()<<" "<<simulator.agents_.size()<<" agents "<<simulator.movingObstacles_.size()<<" agents polygonaux'"<<endl;
plot<<"set xtics ('' -1)"<<endl;
if(percent)
{
plot<<"set terminal svg"<<endl<<"set output 'stats/svg/"<<filename.str().c_str()<<".svg'"<<endl<<"set key top right"<<endl<<"set boxwidth 0.5"<<endl<<
"set ylabel 'Percent of ressource'"<<endl<<"set style fill solid border -1"<<endl<<"set xrange [-1:2]"<<endl<<"set yrange [0:105]"<<endl<<
"plot '"<<data<<"' using 1:($2+$3+$4+$5+$6) with boxes title 'Multires','"<<data<<"' using 1:($3+$4+$5+$6) with boxes title 'MaJ Agent','"<<data<<
"' using 1:($4+$5+$6) with boxes title 'MaJ Agents polgonaux','"<<data<<"' using 1:($5+$6) with boxes title 'Comportement'"<<endl<<"#,'"
<<data<<"' using 1:6 with boxes title 'Rendu'";
}
else
{
plot<<"set terminal svg"<<endl<<"set output 'stats/svg/"<<filename.str().c_str()<<".svg'"<<endl<<"set key top right"<<endl<<"set boxwidth 0.5"<<endl<<
"set ylabel 'time ressource in sec'"<<endl<<"set style fill solid border -1"<<endl<<"set xrange [-1:2]"<<endl<<"set yrange [0:"<<sum+(2*sum/100)<<"]"<<endl<<
"plot '"<<data<<"' using 1:($2+$3+$4+$5+$6) with boxes title 'Multires','"<<data<<"' using 1:($3+$4+$5+$6) with boxes title 'MaJ Agent','"<<data<<
"' using 1:($4+$5+$6) with boxes title 'MaJ Agents polgonaux','"<<data<<"' using 1:($5+$6) with boxes title 'Comportement'"<<endl<<"#,'"
<<data<<"' using 1:6 with boxes title 'Rendu'";
}
plot.close();
}
else // sinon
cerr << "Erreur à l'ouverture !" << endl;
}
exit(0) ;
}
struct timespec begTime ;
clock_gettime(CLOCK_MONOTONIC, &begTime) ;
unsigned long begTime =clock() ;
simulator.doStep() ;
unsigned long endTime =clock() ;
time_update += (endTime - begTime);
struct timespec endTime ;
clock_gettime(CLOCK_MONOTONIC, &endTime) ;
time_update += timespec_delta(begTime,endTime).tv_nsec;
m_positionVBO->updateData(simulator.envMap_.position);
......@@ -1799,6 +1893,7 @@ int main(int argc, char** argv)
unsigned int config = 1 ;
unsigned int nbAgent = 1000;
unsigned int nbObst = 20;
bool multires = true;
if (argc > 6)
......
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