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

int main(int argc, char* argv[])
{
jben's avatar
jben committed
7 8 9

    int c;
    
jben's avatar
jben committed
10
    if(argc<3)
jben's avatar
jben committed
11
    {
jben's avatar
jben committed
12
        fprintf(stderr,"Usage incorrect\n");
jben's avatar
jben committed
13 14
        abort();
    }
jben's avatar
jben committed
15 16 17
    
    std::string s_db = argv[1];
    unsigned int jid = atoi(argv[2]);
jben's avatar
jben committed
18
    
jben's avatar
jben committed
19 20 21 22 23 24
    database D_db(s_db,jid);
    D_db.write_pid();
    
    
    if(D_db.get_state()!=0)
    {
jben's avatar
jben committed
25
        return(1);
jben's avatar
jben committed
26 27 28
    }
    
    D_db.write_state(1); // searching
jben's avatar
jben committed
29

jben's avatar
jben committed
30
    model m_model = D_db.get_model();
jben's avatar
jben committed
31
   
jben's avatar
jben committed
32

jben's avatar
jben committed
33 34

    double d_total_dist_min=0;
jben's avatar
jben committed
35
    std::list<unsigned long long> l_id;
jben's avatar
jben committed
36
    std::list<double> l_dists_min;
jben's avatar
jben committed
37

jben's avatar
jben committed
38

jben's avatar
jben committed
39
    if(!D_db.find_nodes(l_id))
jben's avatar
jben committed
40
    {
jben's avatar
jben committed
41
        D_db.write_state(17);
jben's avatar
jben committed
42 43
        return(1);
    }
jben's avatar
jben committed
44

jben's avatar
jben committed
45 46
    
    unsigned long long previous=0;
jben's avatar
jben committed
47

jben's avatar
jben committed
48 49 50 51
    // 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())
jben's avatar
jben committed
52
        {
jben's avatar
jben committed
53 54 55
            previous=*it_id;
            continue;
        }
jben's avatar
jben committed
56

jben's avatar
jben committed
57 58 59
        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
jben committed
60

jben's avatar
jben committed
61
        previous=*it_id;
jben's avatar
jben committed
62 63

    }
jben's avatar
jben committed
64

65 66 67 68 69 70
    if(d_total_dist_min>100e3)
    {
        D_db.write_state(18);
        return(1);
    }

jben's avatar
jben committed
71
    D_db.write_state(2); // routing
jben's avatar
jben committed
72

jben's avatar
jben committed
73
    previous=0;
jben's avatar
jben committed
74 75
    etat_cycliste e_courant;
    int troncon=0;
jben's avatar
jben committed
76
    double d_status_offset=0;
jben's avatar
jben committed
77

jben's avatar
jben committed
78 79
    std::list<instant> lI_globalres;

jben's avatar
jben committed
80
    std::list<double>::iterator it_dist_min=l_dists_min.begin();
jben's avatar
jben committed
81
    for(std::list<unsigned long long>::iterator it_id=l_id.begin();it_id!=l_id.end();it_id++)
jben's avatar
jben committed
82
    {
jben's avatar
jben committed
83 84 85 86 87 88
        if(it_id==l_id.begin())
        {
            previous=*it_id;
            continue;
        }

jben's avatar
jben committed
89
        double d_status_echelle=(*it_dist_min++)/d_total_dist_min;
jben's avatar
jben committed
90

jben's avatar
jben committed
91
        route r_route(&D_db,m_model,previous,*it_id);
jben's avatar
jben committed
92

jben's avatar
jben committed
93
        r_route.set_status(d_status_echelle,d_status_offset);
jben's avatar
jben committed
94 95 96 97 98
        r_route.set_etat_init(e_courant);
        
        r_route.go();
        
        e_courant=r_route.get_etat_final();
jben's avatar
jben committed
99
        d_status_offset+=d_status_echelle;
jben's avatar
jben committed
100 101


jben's avatar
jben committed
102 103 104 105
        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
106
            lI_globalres.push_back(*it);
jben's avatar
jben committed
107
        }
jben's avatar
jben committed
108 109


jben's avatar
jben committed
110 111
        previous=*it_id;
        troncon++;
jben's avatar
jben committed
112

jben's avatar
jben committed
113
    }
jben's avatar
jben committed
114

jben's avatar
jben committed
115 116
    D_db.write_results(lI_globalres,m_model.d_P);
    D_db.write_state(3); // finito
jben's avatar
jben committed
117

jben's avatar
jben committed
118
    
jben's avatar
jben committed
119 120 121
    return(0);
}