main.cc 5.54 KB
Newer Older
jben's avatar
jben committed
1 2
#include "route.h"
#include "model.h"
jben's avatar
jben committed
3 4
#include "database.h"
#include <getopt.h>
jben's avatar
jben committed
5 6 7

int main(int argc, char* argv[])
{
jben's avatar
jben committed
8 9 10 11 12 13 14 15 16 17 18 19 20

    int c;
    
    std::string s_db;
    double d_VplatKMH=20;
    double d_masse=80;
    double d_SCx=.45;
    double d_Cr=.01;
    double d_rho_air=1.204;
    double d_vent_from=0;
    double d_vent_VKMH=0;
    char mode='e';

jben's avatar
jben committed
21 22 23
    printf("# init\n");
    fflush(stdout);

jben's avatar
jben committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    while (1)
    {
        static struct option long_options[] = {
            {"database",required_argument, 0,  'd' },
            {"speedref",required_argument, 0,  's' },
            {"mass",    required_argument, 0,  'm' },
            {"cr",      required_argument, 0,  'C' },
            {"scx",     required_argument, 0,  'S' },
            {"rho",     required_argument, 0,  'r' },
            {"winddir", required_argument, 0,  'w' },
            {"windspeed",required_argument,0,  'W' },
            {"criterion",required_argument,0,  'c' },
            {0,         0,                 0,  0 }
        };
        int option_index = 0;

        c = getopt_long(argc, argv, "d:s:m:C:S:r:w:W:c:",
                long_options, &option_index);
        if (c == -1)
            break;
        switch (c)
        {
            case 0:
                if (long_options[option_index].flag != 0)
                    break;
        
            case 'd':
                s_db = optarg;
                break;

            case 's':
                d_VplatKMH = atof(optarg);
                if(d_VplatKMH<=0)
                    abort();
                break;

            case 'm':
                d_masse = atof(optarg);
                if(d_masse<=0)
                    abort();
                break;

            case 'C':
                d_Cr = atof(optarg);
                if(d_Cr<0)
                    abort();
                break;

            case 'S':
                d_SCx = atof(optarg);
                if(d_SCx<0)
                    abort();
                break;

            case 'r':
                d_rho_air = atof(optarg);
                if(d_rho_air<0)
                    abort();
                break;

            case 'w':
                d_vent_from = atof(optarg);
                break;

            case 'W':
                d_vent_VKMH = atof(optarg);
                break;

            case 'c':
                if(std::string(optarg)==std::string("energy"))
                    mode='e';
                else if(std::string(optarg)==std::string("distance"))
                    mode='d';
                else
                    abort();
                break;
        }


    }

    std::list< std::pair<double,double> > l_points;

    bool lonoulat=false;
    double lon,lat;
    if (optind < argc)
jben's avatar
jben committed
110
    {
jben's avatar
jben committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        while (optind < argc)
        {
            if(lonoulat)
            {
                lat=atof(argv[optind]);
                l_points.push_back(std::pair<double,double>(lon,lat));
            }
            else
            {
                lon=atof(argv[optind]);
            }



            lonoulat=!lonoulat;
            optind++;
        }
    }

    if(l_points.size()<2)
    {
jben's avatar
jben committed
132 133
        printf("# fatal error: must have at least 2 points\n");
        fflush(stdout);
jben's avatar
jben committed
134 135 136
        abort();
    }

jben's avatar
status  
jben committed
137 138
    
    model m_model(mode,d_VplatKMH,d_masse,d_Cr,d_SCx,d_rho_air,d_vent_from,d_vent_VKMH);
jben's avatar
jben committed
139
   
jben's avatar
jben committed
140 141 142 143

    printf("# searching\n");
    fflush(stdout);

jben's avatar
jben committed
144 145

    double d_total_dist_min=0;
jben's avatar
status  
jben committed
146
    std::list<unsigned long long> l_id;
jben's avatar
jben committed
147
    std::list<double> l_dists_min;
jben's avatar
jben committed
148

jben's avatar
status  
jben committed
149 150
    { // to destroy database object
        database D_db(s_db);
jben's avatar
jben committed
151

jben's avatar
jben committed
152 153
        if(!D_db.find_nodes(l_points, l_id))
            return 17;
jben's avatar
jben committed
154

jben's avatar
status  
jben committed
155
        unsigned long long previous=0;
jben's avatar
jben committed
156

jben's avatar
status  
jben committed
157 158 159 160 161 162 163 164 165
        // calcul des distances pour le status
        for(std::list<unsigned long long>::iterator it_id=l_id.begin();it_id!=l_id.end();it_id++)
        {
            if(it_id==l_id.begin())
            {
                previous=*it_id;
                continue;
            }

jben's avatar
jben committed
166 167 168
            double d_c=m_model.dist_node(D_db.get_node(*it_id),D_db.get_node(previous));
            l_dists_min.push_back(d_c);
            d_total_dist_min+=d_c;
jben's avatar
status  
jben committed
169 170 171 172 173

            previous=*it_id;

        }
    }
jben's avatar
jben committed
174

jben's avatar
jben committed
175 176 177
    printf("# routing\n");
    fflush(stdout);

jben's avatar
jben committed
178 179 180
    unsigned long long previous=0;
    etat_cycliste e_courant;
    int troncon=0;
jben's avatar
status  
jben committed
181
    double d_status_offset=0;
jben's avatar
jben committed
182

jben's avatar
jben committed
183
    std::list<double>::iterator it_dist_min=l_dists_min.begin();
jben's avatar
jben committed
184
    for(std::list<unsigned long long>::iterator it_id=l_id.begin();it_id!=l_id.end();it_id++)
jben's avatar
jben committed
185
    {
jben's avatar
jben committed
186 187 188 189 190 191
        if(it_id==l_id.begin())
        {
            previous=*it_id;
            continue;
        }

jben's avatar
jben committed
192
        double d_status_echelle=(*it_dist_min++)/d_total_dist_min;
jben's avatar
status  
jben committed
193

jben's avatar
jben committed
194
        route r_route(s_db,m_model,previous,*it_id);
jben's avatar
jben committed
195

jben's avatar
status  
jben committed
196
        r_route.set_status(d_status_echelle,d_status_offset);
jben's avatar
jben committed
197 198 199 200 201
        r_route.set_etat_init(e_courant);
        
        r_route.go();
        
        e_courant=r_route.get_etat_final();
jben's avatar
status  
jben committed
202
        d_status_offset+=d_status_echelle;
jben's avatar
jben committed
203 204


jben's avatar
jben committed
205 206 207 208
        std::list<instant> & lI_result = r_route.get_result();
        
        for(std::list<instant>::iterator it=lI_result.begin();it!=lI_result.end();it++)
        {
jben's avatar
jben committed
209 210
            printf("# node: ");
            printf("%i\t",troncon);
jben's avatar
jben committed
211 212 213
            printf("%llu\t",it->ull_id);
            printf("%f\t%f\t%f\t",it->d_lon,it->d_lat,it->d_height);
            printf("%llu\t%lu\t",it->ull_way_from_id,it->ull_way_from_rev);
jben's avatar
jben committed
214
            printf("%f\t%f\t%f\t%f\t%f",it->d_V * 3.6,it->d_dist,it->d_deniv_pos,it->d_ET,it->d_ET/m_model.d_P);
jben's avatar
jben committed
215 216
            printf("\n");
        }
jben's avatar
jben committed
217 218
        printf("# section: %i\n",troncon);
        fflush(stdout);
jben's avatar
jben committed
219 220


jben's avatar
jben committed
221 222
        previous=*it_id;
        troncon++;
jben's avatar
jben committed
223

jben's avatar
jben committed
224
    }
jben's avatar
jben committed
225

jben's avatar
jben committed
226
    
jben's avatar
jben committed
227 228 229
    return(0);
}