Changeset 4022:e4f1c444a6f8 in orange
 Timestamp:
 07/25/07 23:40:47 (7 years ago)
 Branch:
 default
 Convert:
 1ab94fc29a053901f394da2470d05ce8efacea8b
 Location:
 source/orangeom
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

source/orangeom/networkoptimization.cpp
r4021 r4022 83 83 } 84 84 85 int TNetworkOptimization::circularCrossingReduction() 86 { 87 // TODO!!! 88 vector<QueueVertex*> vertices; 89 vector<QueueVertex*> original; 90 91 int i; 92 for (i = 0; i < nVertices; i++) 93 { 94 vector<int> neighbours; 95 graphStructure>getNeighbours(i, neighbours); 96 97 QueueVertex *vertex = new QueueVertex(); 98 vertex>ndx = i; 99 vertex>unplacedNeighbours = neighbours.size(); 100 vertex>neighbours = neighbours; 101 102 vertices.push_back(vertex); 103 } 104 original.assign(vertices.begin(), vertices.end()); 105 106 vector<int> positions; 107 while (vertices.size() > 0) 108 { 109 sort(vertices.begin(), vertices.end(), QueueVertex()); 110 111 cout << "vertices" << endl; 112 for (i = 0; i < vertices.size(); i++) 113 cout << *vertices[i] << endl; 114 115 QueueVertex *vertex = vertices.back(); 116 positions.push_back(vertex>ndx); 117 //cout << "size: " << vertex>neighbours.size() <<endl; 118 cout << "ndx: " << vertex>ndx << endl; 119 int j; 120 for (j = 0; j < vertex>neighbours.size(); j++) 121 { 122 int ndx = vertex>neighbours[j]; 123 124 original[ndx]>placedNeighbours++; 125 original[ndx]>unplacedNeighbours; 126 } 127 128 vertices.pop_back(); 129 } 130 131 cout << "original" << endl; 132 for (i = 0; i < original.size(); i++) 133 cout << *original[i] << endl; 134 135 cout << "positions" << endl; 136 for (i = 0; i < positions.size(); i++) 137 cout << positions[i] << endl; 138 139 140 int xCenter = width / 2; 141 int yCenter = height / 2; 142 int r = (width < height) ? width * 0.38 : height * 0.38; 143 144 double fi = PI; 145 double step = 2 * PI / nVertices; 146 147 for (i = 0; i < nVertices; i++) 148 { 149 pos[positions[i]][0] = r * cos(fi) + xCenter; 150 pos[positions[i]][1] = r * sin(fi) + y Center; 151 152 fi = fi  step; 153 } 154 155 for (vector<QueueVertex*>::iterator i = original.begin(); i != original.end(); ++i) 156 delete *i; 157 158 original.clear(); 159 vertices.clear(); 160 161 return 0; 162 } 85 163 86 164 // type … … 107 185 if (type == 0) 108 186 { 109 pos[i][0] = r * cos(fi) + width;110 pos[i][1] = r * sin(fi) + height;187 pos[i][0] = r * cos(fi) + xCenter; 188 pos[i][1] = r * sin(fi) + yCenter; 111 189 } 112 190 else if (type == 1) … … 114 192 int ndx = rand() % vertices.size(); 115 193 116 pos[vertices[ndx]][0] = r * cos(fi) + width;117 pos[vertices[ndx]][1] = r * sin(fi) + height;194 pos[vertices[ndx]][0] = r * cos(fi) + xCenter; 195 pos[vertices[ndx]][1] = r * sin(fi) + yCenter; 118 196 119 197 vertices.erase(vertices.begin() + ndx); … … 285 363 kk = 2 * k; 286 364 double kk2 = kk * kk; 287 cout << "Miha" << endl;288 365 // iterations 289 366 for (i = 0; i < steps; i++) … … 782 859 } 783 860 861 862 PyObject *NetworkOptimization_circularCrossingReduction(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "() > None") 863 { 864 PyTRY 865 CAST_TO(TNetworkOptimization, graph); 866 graph>circularCrossingReduction(); 867 RETURN_NONE; 868 PyCATCH 869 } 784 870 PyObject *NetworkOptimization_fruchtermanReingold(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(steps, temperature, hiddenNodes) > temperature") 785 871 { 
source/orangeom/networkoptimization.hpp
r4021 r4022 45 45 #include "graph.hpp" 46 46 #include "stringvars.hpp" 47 #include <queue> 47 48 48 49 using namespace std; … … 67 68 int radialFruchtermanReingold(int steps, int nCircles); 68 69 int circular(int type); 70 int circularCrossingReduction(); 69 71 //int circularRandom(); 70 72 double getTemperature() {return temperature;} … … 94 96 }; 95 97 98 99 class QueueVertex 100 { 101 public: 102 int ndx; 103 unsigned int unplacedNeighbours; 104 unsigned int placedNeighbours; 105 vector<int> neighbours; 106 107 friend ostream & operator<<(ostream &os, const QueueVertex &v) 108 { 109 os << "ndx: " << v.ndx << " unplaced: " << v.unplacedNeighbours << " placed: " << v.placedNeighbours << " neighbours: "; 110 int i; 111 for (i = 0; i < v.neighbours.size(); i++) 112 os << v.neighbours[i] << " "; 113 114 return (os); 115 } 116 117 QueueVertex(int index = 1, unsigned int neighbours = 0) 118 { 119 ndx = index; 120 unplacedNeighbours = neighbours; 121 placedNeighbours = 0; 122 } 123 124 bool operator () (const QueueVertex * a, const QueueVertex * b) 125 { 126 if (a>unplacedNeighbours < b>unplacedNeighbours) 127 return false; 128 else if (a>unplacedNeighbours > b>unplacedNeighbours) 129 return true; 130 else 131 { 132 return a>placedNeighbours < b>placedNeighbours; 133 } 134 } 135 }; 136 96 137 #endif
Note: See TracChangeset
for help on using the changeset viewer.