idlHistogram.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 *
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2014, ISR University of Coimbra.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of the ISR University of Coimbra nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 * Author: Luca Iocchi (2014-2016)
00036 *********************************************************************/
00037 
00038 #include <stdlib.h>
00039 #include <math.h>
00040 #include <vector>
00041 #include <fstream>
00042 #include <sstream>
00043 #include <iostream>
00044 #include <cstring>
00045 
00046 using namespace std;
00047 
00048 #define RESOLUTION 1.0 // seconds
00049 
00050 #define MAXIDLENESS 500.0 // seconds
00051 
00052 int main (int argc, char **argv)
00053 {   
00054     if (argc<2) {
00055         cout << "Use: " << argv[0] << " <filename> " << endl;
00056         exit(-1);
00057     }
00058     
00059     int n = (int)(MAXIDLENESS/RESOLUTION)+1;
00060     int v[n]; for (int k=0; k<n; k++) v[k]=0;
00061     
00062     ifstream f;
00063     f.open(argv[1]);
00064     
00065     double time,idleness; int robot,node,interferences; char ch;
00066     int sum=0;
00067     while (f.good()) {
00068         char line[80];
00069         f.getline(line,80);
00070         stringstream ss(line);
00071         // current_time, id_robot, goal, current_idleness[goal], interferences
00072         ss >> time; ss>>ch;
00073         ss >> robot; ss>>ch;
00074         ss >> node; ss>>ch;
00075         ss >> idleness; ss>>ch;
00076         ss >> interferences;
00077         
00078         // cout << idleness << endl;
00079         
00080         if (idleness>MAXIDLENESS) {
00081            cout << "WARNING: Idleness " << idleness << " out of range! Discarded!" << endl; 
00082         }
00083         else {
00084             int b = (int)(idleness/RESOLUTION);
00085             v[b]++; sum++;
00086         }
00087     }
00088     f.close();
00089     
00090     char nf[strlen(argv[1])+8], cnf[strlen(argv[1])+8];
00091     strcpy(nf,argv[1]);
00092     nf[strlen(nf)-4]='\0';
00093     strcpy(cnf,nf);
00094     strcat(nf,".hist");
00095     strcat(cnf,".chist");
00096     cout << "Histogram output file: " << nf << endl;
00097     ofstream of1; of1.open(nf);
00098     ofstream of2; of2.open(cnf);
00099     double c=0;
00100     for (int k=0; k<n; k++) {
00101         of1 << k*RESOLUTION << " " << (double)v[k]/sum << endl;
00102         c += (double)v[k]/sum;
00103         of2 << k*RESOLUTION << " " << c << endl;
00104     }
00105     
00106     of1.close();   of2.close();
00107     
00108 }
00109 
00110 /*
00111  * 
00112  * 
00113  * 
00114     gnuplot> plot ("results/idl_grid_4_RAND.csv.hyst") w li
00115     gnuplot> replot ("results/idl_grid_4_DTAG.csv_OLD.hyst") w li
00116 
00117  * 
00118  * 
00119  * 
00120  * 
00121  */
00122 
00123 


patrolling_sim
Author(s):
autogenerated on Mon Oct 2 2017 03:13:50