Bonjour, J'ai fais un programme pour la lecture des graphes à partir d'un fichier:
Code x : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
t # 0
v 0 0
v 1 3
v 2 9
e 2 1 68
e 0 1 10
e 0 2 4
t # 1
v 0 2
v 1 11
v 2 6
v 3 10
v 4 18
v 5 14
e 0 1 15
e 2 5 19
e 1 3 20
t # 2
v 0 6
v 1 11
e 0 1 13
t # 3
v 0 2
v 1 11
v 2 19
v 3 2
e 0 1 15
e 1 2 11
e 0 3 19
t # 4
v 0 1
v 1 16
v 2 14
e 0 1 8
e 1 2 5
e 0 2 19

et je veux l'améliorer surtout en ce qui concerne le temps d’exécution, donc j'ai pensé à utiliser le multithreading mais j'ai aucune idée d'où commencer. J'ai lu quelques exemples (la plupart utilise les méthodes et les fonctions qui ne sont pas dans mon programme).

J'attends vos propositions.

voila le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/vf2_sub_graph_iso.hpp>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
using namespace boost;
 
/*********************************************/
// vertex
struct VertexProperties {
    int id;
    int label;
    VertexProperties(unsigned i=0, unsigned l=0) : id(i), label(l) {}
};
 
// edge
struct EdgeProperties {
    unsigned id;
    unsigned label;
    EdgeProperties(unsigned i=0, unsigned l=0) : id(i), label(l) {}
};
 
// Graph
struct GraphProperties {
    unsigned id;
    unsigned label;
    GraphProperties(unsigned i=0, unsigned l=0) : id(i), label(l) {}
};
 
// adjency list
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
        VertexProperties,
        EdgeProperties,
        GraphProperties> Graph;
 
// descriptors
 
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef std::pair<boost::graph_traits<Graph>::edge_descriptor, bool> edge_t;
// iterators
typedef graph_traits<Graph>::vertex_iterator vertex_iter;
typedef graph_traits<Graph>::edge_iterator edge_iter;
 
int main()
{
    clock_t start=std::clock();
    std::vector<Graph> dataG;
 
    std::ifstream file_reader("1000.data"); // flux d'entrée pour opérer sur les fichiers.
    //ifstream * file_reader= new ifstream("60.txt" ); //flux d'entrée pour opérer sur les fichiers.
 
    std::string line;
    while (std::getline(file_reader, line)) { // getline reads characters from an input stream and places them into a string
 
        char lineType;
 
        std::stringstream ss(line);  // use a string buffer that contains a sequence of characters.
        if (ss >> lineType) switch (lineType) {
            case 't':
                {
                    char diez;
                    unsigned gid;
                    if (ss >> diez >> gid) {
                        dataG.emplace_back(GraphProperties (gid, gid));
                        //dataG.push_back(GraphProperties (gid, gid));
                    }
                    else throw std::runtime_error("Error parsing '" + line + "'");
                }
                break;
            case 'v':
                {
                    assert(!dataG.empty());
 
                    int vId, vLabel;
                    if (ss >> vId >> vLabel) {
                        boost::add_vertex(VertexProperties(vId, vLabel), dataG.back());
                    }
                    else throw std::runtime_error("Error parsing '" + line + "'");
                }
                break;
            case 'e':
                {
                    assert(!dataG.empty());
 
                    int fromId, toId, vLabel;
                    if (ss >> fromId >> toId >> vLabel) {
                        // Note that the EdgeProperty.id doesn't make sense with your input data
                        // as it only contains [vertexFrom vertexTo edgeData]
                        boost::add_edge(fromId, toId, EdgeProperties(vLabel, vLabel), dataG.back());
                    }
                    else throw std::runtime_error("Error parsing '" + line + "'");
                }
                break;
        } else
        {
            // ignoring empty line
        }
    }
}