OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [remove_cycle/] [agony/] [graph.h] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
#ifndef GRAPH_H
2
#define GRAPH_H
3
 
4
#include <stdint.h>
5
#include <vector>
6
#include <list>
7
#include <stdio.h>
8
 
9
#include "queue.h"
10
 
11
class graph {
12
        public:
13
                graph() {}
14
 
15
                graph(uint32_t n, uint32_t m) {reset(n, m);}
16
                graph(const graph & g);
17
 
18
                void reset(uint32_t n, uint32_t m);
19
                void copy(const graph & g);
20
 
21
                struct edge;
22
 
23
                TAILQ_HEAD(edgelist, edge);
24
 
25
                struct node {
26
                        uint32_t id;
27
                        edgelist out, in;
28
                        uint32_t ind, outd;
29
                };
30
 
31
                struct edge {
32
                        node *parent, *child;
33
                        uint32_t id;
34
                        bool bound;
35
                        TAILQ_ENTRY(edge) from, to;
36
                };
37
 
38
                void bind(uint32_t k, uint32_t n, uint32_t m) {bind(getedge(k), getnode(n), getnode(m));}
39
 
40
                void
41
                bind(edge *e, node *n, node *m)
42
                {
43
                        TAILQ_INSERT_TAIL(&n->out, e, from);
44
                        TAILQ_INSERT_TAIL(&m->in, e, to);
45
                        n->outd++;
46
                        m->ind++;
47
                        e->bound = true;
48
                        e->parent = n;
49
                        e->child = m;
50
                }
51
 
52
                void
53
                unbind(edge *e)
54
                {
55
                        TAILQ_REMOVE(&e->parent->out, e, from);
56
                        TAILQ_REMOVE(&e->child->in, e, to);
57
                        e->parent->outd--;
58
                        e->child->ind--;
59
                        e->bound = false;
60
                }
61
 
62
                void
63
                unbind(node *n)
64
                {
65
                        while (!TAILQ_EMPTY(&n->out)) unbind(TAILQ_FIRST(&n->out));
66
                        while (!TAILQ_EMPTY(&n->in)) unbind(TAILQ_FIRST(&n->in));
67
                }
68
 
69
                node * getnode(uint32_t i) {return &m_nodes[i];}
70
                edge * getedge(uint32_t i) {return &m_edges[i];}
71
 
72
        protected:
73
                const graph & operator = (const graph & ) {return *this;}
74
                typedef std::vector<node> nodevector;
75
                typedef std::vector<edge> edgevector;
76
 
77
                nodevector m_nodes;
78
                edgevector m_edges;
79
};
80
 
81
class agony
82
{
83
        public:
84
 
85
                struct node {
86
                        uint32_t id;
87
                        uint32_t label;
88
 
89
                        uint32_t rank;
90
                        uint32_t newrank;
91
                        uint32_t diff;
92
 
93
                        node *parent;
94
                        uint32_t paredge;
95
 
96
                        uint32_t count;
97
 
98
                        TAILQ_ENTRY(node) entries, active;
99
                };
100
 
101
                TAILQ_HEAD(nodehead, node);
102
 
103
                struct edge {
104
                        bool eulerian;
105
                        uint32_t id;
106
                        uint32_t slack;
107
 
108
                        TAILQ_ENTRY(edge) entries;
109
                };
110
 
111
                TAILQ_HEAD(edgehead, edge);
112
 
113
                uint32_t size() const {return m_nodes.size();}
114
                node * getnode(uint32_t i) {return &m_nodes[i];}
115
                edge * getedge(uint32_t i) {return &m_edges[i];}
116
 
117
                void cycledfs();
118
 
119
                void initagony();
120
                void initrank();
121
 
122
                void read(FILE *f);
123
                void writeagony(FILE *f);
124
 
125
                void relief(uint32_t edge);
126
 
127
                void minagony();
128
 
129
                uint32_t primal() const {return m_primal;}
130
                uint32_t dual() const {return m_dual;}
131
 
132
                uint32_t cost();
133
 
134
 
135
        protected:
136
                uint32_t slack(node *v, node *u) const {return u->rank > v->rank + 1 ? u->rank - v->rank - 1 : 0;}
137
                uint32_t newslack(node *v, node *u) const {return u->newrank > v->newrank + 1 ? u->newrank - v->newrank - 1 : 0;}
138
 
139
                uint32_t slack(uint32_t eid) {return slack(from(eid), to(eid));}
140
 
141
                void deleteslack(uint32_t eid);
142
                void addslack(uint32_t eid);
143
 
144
                typedef std::vector<node> nodevector;
145
                typedef std::vector<edge> edgevector;
146
                typedef std::vector<nodehead> nodequeue;
147
                typedef std::vector<edgehead> edgequeue;
148
 
149
                typedef std::list<node *> nodelist;
150
 
151
                void updaterelief(nodelist & nl);
152
                void resetrelief(nodelist & nl);
153
                void shiftrank(nodelist & nl, uint32_t s);
154
                void extractcycle(uint32_t edge);
155
 
156
                node *from(uint32_t eid) {return getnode(m_graph.getedge(eid)->parent->id);}
157
                node *to(uint32_t eid) {return getnode(m_graph.getedge(eid)->child->id);}
158
 
159
 
160
                nodevector m_nodes;
161
                edgevector m_edges;
162
 
163
                graph m_graph;
164
                graph m_dag, m_euler;
165
 
166
                edgequeue m_slacks;
167
                int32_t m_curslack;
168
 
169
                uint32_t m_dual;
170
                uint32_t m_primal;
171
                //uint32_t m_minid;
172
};
173
 
174
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.