-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrease.cpp
751 lines (728 loc) · 18.3 KB
/
decrease.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
#include <iostream>
#include <fstream>
#include <vector>
#include <opencv2/core/core.hpp>
#include<opencv2/opencv.hpp>
#include<algorithm>
#include<string>
#include<ctime>
#include <list>
#include<numeric>
#include<queue>
#include<set>
#include<functional>
#include "minist.h"
using namespace std;
using namespace cv;
#define Maxsize 600
//邻接表中节点,每个节点与该节点对应的索引号指定一条边
struct Node
{
int u; //边终点节点号
double w; //边权值
Node(int a, double b) :u(a), w(b) {}
};
struct Record
{
int pre;
double cost;
};
vector<Record> Path;
class Cost_Distance
{
public:
int node_i;
int node_j;
double cost_distance;
Cost_Distance(int i, int j, double distance_)
{
node_i = i;
node_j = j;
cost_distance = distance_;
}
bool operator < (const Cost_Distance &other) const
{
return this->cost_distance < other.cost_distance;
}
bool operator > (const Cost_Distance &other) const
{
return this->cost_distance > other.cost_distance;
}
};
void savePCA(const string &file_name, cv::PCA pca_)
{
FileStorage fs(file_name, FileStorage::WRITE);
fs << "mean" << pca_.mean;
fs << "e_vectors" << pca_.eigenvectors;
fs << "e_values" << pca_.eigenvalues;
fs.release();
}
typedef priority_queue<Cost_Distance, vector<Cost_Distance>, greater<Cost_Distance>> min_Cost;
void loadPCA(const string &file_name, PCA &pca_)
{
FileStorage fs2(file_name, FileStorage::READ);
fs2["mean"] >> pca_.mean;
fs2["e_vectors"] >> pca_.eigenvectors;
fs2["e_values"] >> pca_.eigenvalues;
fs2.release();
}
double distance_node(Mat &point1, Mat &point2)
{
assert(point1.cols == point2.cols);
double distance = 0.0;
for (int i = 0; i < point1.cols; i++)
{
double vec = point1.at<double>(0, i) - point2.at<double>(0, i);
distance += vec*vec;
}
return distance;
}
void Dijstra(vector<list<Node>> &GraphAdj, int s) //最短路径dijstra算法,s为源节点
{
vector<bool> isUsed(GraphAdj.size(), false);
list<int> Assi;
Path.assign(GraphAdj.size(), Record());
for (int i = 0; i < GraphAdj.size(); i++)
{
Path[i].pre = i;
Path[i].cost = INT_MAX;
}
isUsed[s] = true;
for (auto it = GraphAdj[s].begin(); it != GraphAdj[s].end(); it++)
{
Path[it->u].pre = s;
Path[it->u].cost = it->w;
Assi.push_back(it->u);
}
while (!Assi.empty())
{
list<int>::iterator It;
int mincost = INT_MAX;
for (auto it = Assi.begin(); it != Assi.end(); it++)
{
if (mincost > Path[*it].cost)
{
mincost = Path[*it].cost;
It = it;
}
}
int u = *It;
Assi.erase(It);
isUsed[u] = true;
for (auto it = GraphAdj[u].begin(); it != GraphAdj[u].end(); it++)
{
if (isUsed[it->u]) continue;
if (Path[it->u].cost == INT_MAX) Assi.push_back(it->u);
if (Path[it->u].cost > mincost + it->w)
{
Path[it->u].cost = mincost + it->w;
Path[it->u].pre = u;
}
}
}
}
void Traverse(int k)
{
if (Path[k].pre == k) { cout << k; return; }
Traverse(Path[k].pre);
cout << " " << k;
}
void Print(int s, int n) //输出最短路径,s为源节点,n为总的节点数
{
cout << "Result:\n";
for (int i = 0; i < 10; i++)
{
if (i == s) continue;
cout << "From " << s << " to " << i << ": ";
if (Path[i].cost == INT_MAX)
{
cout << "No path\n\n"; continue;
}
Traverse(i);
cout << endl;
cout << "Minimal Cost: " << Path[i].cost << endl << endl;
}
}
//void Create_Min_Cost(Mat &pt, vector<list<Node>> &GraphAdj, min_Cost &min_heap)
//{
// Mat pt1, pt2;
// for (int i = 0; i <GraphAdj.size(); i++)
// {
// for (int j = 0; j < GraphAdj.size(); j++)
// {
// double Sum_distance=0.0;
// double distance_1=0.0; //i与j联通的点的间接距离
// double distance_2 = 0.0; //i与j联通的点的直接距离
// for (auto iter = GraphAdj[i].begin(); iter != GraphAdj[i].end(); iter++)
// {
// if (iter->u == j)
// {
// for (auto iter1 = GraphAdj[iter->u].begin(); iter1 != GraphAdj[iter->u].end(); iter1++)
// {
// if (iter1->u != i)
// {
// distance_1 = iter->w + iter1->w;
// pt.row(i).copyTo(pt1);
// pt.row(iter1->u).copyTo(pt2);
// distance_2 = distance_node(pt1, pt2);
// Sum_distance += (distance_2 - distance_1)*(distance_2 - distance_1);
// }
// }
// min_heap.push(Cost_Distance(i, iter->u, Sum_distance));
// }
// }
// }
// }
//}
double cal_cost(Mat &pt, vector<list<Node>> &GraphAdj, int n, int m)
{
<<<<<<< HEAD
Mat pt1, pt2, pt3;
=======
Mat pt1, pt2,pt3;
>>>>>>> origin/master
double distance_1 = 0.0;
double distance_2 = 0.0;
double Sum_distance = 0.0;
for (auto iter = GraphAdj[m].begin(); iter != GraphAdj[m].end(); iter++)
{
if (iter->u != n)
{
<<<<<<< HEAD
pt.row(n).copyTo(pt1);
pt.row(iter->u).copyTo(pt2);
pt.row(m).copyTo(pt3);
distance_1 = distance_node(pt1, pt3) + iter->w; //n与m相连的距离+m与m的连接点相连的距离
=======
pt.row(n).copyTo(pt1);
pt.row(iter->u).copyTo(pt2);
pt.row(m).copyTo(pt3);
distance_1 = distance_node(pt1,pt3)+ iter->w; //n与m相连的距离+m与m的连接点相连的距离
>>>>>>> origin/master
distance_2 = distance_node(pt1, pt2); //n与m的连接点直接连的距离
Sum_distance += (distance_2 - distance_1)*(distance_2 - distance_1);
}
}
return Sum_distance;
}
void Decrease_node(Mat &pt, vector<list<Node>> &GraphAdj, vector<Cost_Distance> &min_heap)
{
Mat pt1, pt2;
vector<int> index1;
vector<int> index2;
vector<list<Node>> result;
index1.assign(GraphAdj.size(), 0); //要删除点的序号
index2.assign(GraphAdj.size(), 0); //要保留点的序号
double distance;
double dis_cost;
double dis_cost1;
<<<<<<< HEAD
cout << min_heap.size() << endl;
for (int i = 0;i<500; i++)
{
int t = min_heap[0].node_i; //要保留的点的序号
int k = min_heap[0].node_j; //要删除的点的序号
=======
for (int i = 0; i < 200; i++)
{
int t = min_heap[0].node_i; //要保留的点
int k = min_heap[0].node_j; //要删除的点
//if (index1[k] == 1)
//{
// min_heap.erase(min_heap.begin());
// continue;
//}
>>>>>>> origin/master
index1[k] = 1;
index2[t] = 1;
index2[k] = 0;
pt.row(t).copyTo(pt2);
bool flag = true;
<<<<<<< HEAD
/*for (auto iter = GraphAdj[t].begin(); iter != GraphAdj[t].end(); iter++)
=======
for (auto iter = GraphAdj[t].begin(); iter != GraphAdj[t].end(); iter++)
>>>>>>> origin/master
{
if (iter->u == k)
{
iter = GraphAdj[t].erase(iter);
break;
}
<<<<<<< HEAD
}*/
for (auto it = min_heap.begin(); it != min_heap.end(); )
{
if (it->node_j == k || it->node_i == k)
=======
}
for (auto it = min_heap.begin(); it != min_heap.end(); )
{
if (it->node_j == k||it->node_i==k)
>>>>>>> origin/master
{
it = min_heap.erase(it);
continue;
}
<<<<<<< HEAD
else
{
it++;
}
}
/*if (min_heap.size() == 0)
{
cout << i << endl;
break;
}*/
for (auto iter = GraphAdj[k].begin(); iter != GraphAdj[k].end(); )
{
pt.row(iter->u).copyTo(pt1);
distance = distance_node(pt1, pt2);
flag = true;
for (auto iter1 = GraphAdj[t].begin(); iter1 != GraphAdj[t].end(); iter1++) //防止重复插入
{
if (iter1->u == iter->u || iter->u == t)
{
flag = false;
break;
}
}
for (auto iter3 = GraphAdj[iter->u].begin(); iter3 != GraphAdj[iter->u].end(); iter3++)
{
if (iter3->u == k)
{
iter3 = GraphAdj[iter->u].erase(iter3);
break;
=======
it++;
}
for (auto iter = GraphAdj[k].begin(); iter != GraphAdj[k].end(); iter++)
{
pt.row(iter->u).copyTo(pt1);
distance = distance_node(pt1, pt2);
for (auto iter1 = GraphAdj[t].begin(); iter1 != GraphAdj[t].end(); iter1++) //防止重复插入
{
flag = true;
if (iter1->u == iter->u||iter->u==t)
{
flag = false;
break;
>>>>>>> origin/master
}
}
if (flag == true)
{
GraphAdj[t].push_back(Node(iter->u, distance));
GraphAdj[iter->u].push_back(Node(t, distance));
<<<<<<< HEAD
dis_cost = cal_cost(pt, GraphAdj, t, iter->u);
dis_cost1 = cal_cost(pt, GraphAdj, iter->u, t);
for (auto iter2 = min_heap.begin(); iter2 != min_heap.end(); iter2++)
{
if (min_heap.size() == 0)
{
iter2 = min_heap.insert(iter2, Cost_Distance(t, iter->u, dis_cost));
break;
}
=======
dis_cost = cal_cost(pt, GraphAdj,t,iter->u);
dis_cost1 = cal_cost(pt, GraphAdj, iter->u, t);
for (auto iter2 = min_heap.begin(); iter2 != min_heap.end(); iter2++)
{
>>>>>>> origin/master
if (iter2->cost_distance <= dis_cost)
continue;
else
{
iter2 = min_heap.insert(iter2, Cost_Distance(t, iter->u, dis_cost));
break;
}
}
for (auto iter2 = min_heap.begin(); iter2 != min_heap.end(); iter2++)
{
<<<<<<< HEAD
if (min_heap.size() == 0)
{
iter2 = min_heap.insert(iter2, Cost_Distance(t, iter->u, dis_cost));
break;
}
=======
>>>>>>> origin/master
if (iter2->cost_distance <= dis_cost1)
continue;
else
{
iter2 = min_heap.insert(iter2, Cost_Distance(iter->u, t, dis_cost1));
break;
}
}
<<<<<<< HEAD
iter = GraphAdj[k].erase(iter);
continue;
=======
>>>>>>> origin/master
}
iter++;
}
<<<<<<< HEAD
/* if (accumulate(index2.begin(), index2.end(), 0) == 92)
{
cout << i << endl;
break;
}*/
=======
>>>>>>> origin/master
}
cout << min_heap.size() << endl;
/*for (int i = 0; i < GraphAdj.size(); i++)
{
if (index1[i] == 1)
{
index2[i] = 0;
}
<<<<<<< HEAD
}*/
cout << accumulate(index2.begin(), index2.end(), 0) << endl;
/*for (int i = 0, j = 0; i < GraphAdj.size(); i++)
=======
}
for (int i = 0,j=0; i < GraphAdj.size(); i++)
>>>>>>> origin/master
{
if (index2[i] == 1)
{
cout << i << " : ";
result.push_back(GraphAdj[i]);
for (auto iter = result[j].begin(); iter != result[j].end(); iter++)
{
if (iter->u != NULL)
{
cout << iter->u << " ";
}
}
cout << endl;
j = j + 1;
<<<<<<< HEAD
}
}*/
//cout << min_heap.size() << endl;
}
void Heapadjust(vector<Cost_Distance> &heap, int currentPos, int end)//建立最小堆
{
int i = currentPos, j = 2 * i;
Cost_Distance temp = heap[i];
while (j <= end)
{
if (j < end&&heap[j].cost_distance > heap[j + 1].cost_distance)
++j;
if (temp.cost_distance <= heap[j].cost_distance)
break;
heap[i] = heap[j];
i = j;
j = j * 2;
}
heap[i] = temp;
}
void swap(vector<Cost_Distance> &heap, int i, int j)// 输出最小堆时使用的交换程序
{
Cost_Distance temp = heap[i];
heap[i] = heap[j];
heap[j] = temp;
}
void Create_minheap(Mat &pt, vector<list<Node>> &GraphAdj, vector<Cost_Distance> &heap_final)//建立最小堆
{
Mat pt1, pt2;
vector<Cost_Distance> heap;
heap.push_back(Cost_Distance(0, 0, 0));
for (int i = 0; i < GraphAdj.size(); i++)
{
double distance_1 = 0.0; //i与j联通的点的间接距离
double distance_2 = 0.0; //i与j联通的点的直接距离
for (auto iter = GraphAdj[i].begin(); iter != GraphAdj[i].end(); iter++)
{
double Sum_distance = 0.0;
for (auto iter1 = GraphAdj[iter->u].begin(); iter1 != GraphAdj[iter->u].end(); iter1++)
{
if (iter1->u != i)
{
distance_1 = iter->w + iter1->w;
pt.row(i).copyTo(pt1);
pt.row(iter1->u).copyTo(pt2);
distance_2 = distance_node(pt1, pt2);
Sum_distance += (distance_2 - distance_1)*(distance_2 - distance_1);
}
}
heap.push_back(Cost_Distance(i, iter->u, Sum_distance));
}
}
int k = heap.size() - 1;
int currentPos = k / 2;
while (currentPos > 0)
{
Heapadjust(heap, currentPos, k);
--currentPos;
}
for (int i = k; i>0; i--)
{
swap(heap, 1, i);
heap_final.push_back(heap[i]);
Heapadjust(heap, 1, i - 1);
}
//for (int i = 0; i < 5; i++)
//{
// cout << heap_final[i].node_i << " " << heap_final[i].node_j << " " << heap_final[i].cost_distance;
// cout << endl;
//}
//cout << heap_final.size()<<endl;
}
void Create_Min_Cost(Mat &pt, vector<list<Node>> &GraphAdj, min_Cost &min_heap)//建立优先级队列
{
Mat pt1, pt2;
=======
}
}
cout << min_heap.size() << endl;
}
void Heapadjust(vector<Cost_Distance> &heap, int currentPos,int end)//建立最小堆
{
int i = currentPos, j = 2 * i;
Cost_Distance temp = heap[i];
while (j <= end)
{
if (j < end&&heap[j].cost_distance > heap[j+1].cost_distance)
++j;
if (temp.cost_distance <= heap[j].cost_distance)
break;
heap[i] = heap[j];
i = j;
j = j * 2;
}
heap[i] = temp;
}
void swap(vector<Cost_Distance> &heap, int i, int j)// 输出最小堆时使用的交换程序
{
Cost_Distance temp = heap[i];
heap[i] = heap[j];
heap[j] = temp;
}
void Create_minheap(Mat &pt, vector<list<Node>> &GraphAdj,vector<Cost_Distance> &heap_final)//建立最小堆
{
Mat pt1, pt2;
vector<Cost_Distance> heap;
heap.push_back(Cost_Distance(0,0,0));
>>>>>>> origin/master
for (int i = 0; i < GraphAdj.size(); i++)
{
double distance_1 = 0.0; //i与j联通的点的间接距离
<<<<<<< HEAD
double distance_2 = 0.0; //i与j联通的点的直接距离
=======
double distance_2 = 0.0; //i与j联通的点的直接距离
>>>>>>> origin/master
for (auto iter = GraphAdj[i].begin(); iter != GraphAdj[i].end(); iter++)
{
double Sum_distance = 0.0;
for (auto iter1 = GraphAdj[iter->u].begin(); iter1 != GraphAdj[iter->u].end(); iter1++)
{
if (iter1->u != i)
{
distance_1 = iter->w + iter1->w;
pt.row(i).copyTo(pt1);
pt.row(iter1->u).copyTo(pt2);
distance_2 = distance_node(pt1, pt2);
Sum_distance += (distance_2 - distance_1)*(distance_2 - distance_1);
}
}
<<<<<<< HEAD
min_heap.push(Cost_Distance(i, iter->u, Sum_distance));
}
=======
heap.push_back(Cost_Distance(i, iter->u, Sum_distance));
}
}
int k = heap.size()-1;
int currentPos = k / 2;
while (currentPos > 0)
{
Heapadjust(heap, currentPos, k);
--currentPos;
}
for (int i = k; i>0; i--)
{
swap(heap, 1, i);
heap_final.push_back(heap[i]);
Heapadjust(heap, 1, i - 1);
}
//for (int i = 0; i < 5; i++)
//{
// cout << heap_final[i].node_i << " " << heap_final[i].node_j << " " << heap_final[i].cost_distance;
// cout << endl;
//}
//cout << heap_final.size()<<endl;
}
void Create_Min_Cost(Mat &pt, vector<list<Node>> &GraphAdj, min_Cost &min_heap)//建立优先级队列
{
Mat pt1, pt2;
for (int i = 0; i < GraphAdj.size(); i++)
{
double distance_1 = 0.0; //i与j联通的点的间接距离
double distance_2 = 0.0; //i与j联通的点的直接距离
for (auto iter = GraphAdj[i].begin(); iter != GraphAdj[i].end(); iter++)
{
double Sum_distance = 0.0;
for (auto iter1 = GraphAdj[iter->u].begin(); iter1 != GraphAdj[iter->u].end(); iter1++)
{
if (iter1->u != i)
{
distance_1 = iter->w + iter1->w;
pt.row(i).copyTo(pt1);
pt.row(iter1->u).copyTo(pt2);
distance_2 = distance_node(pt1, pt2);
Sum_distance += (distance_2 - distance_1)*(distance_2 - distance_1);
}
}
min_heap.push(Cost_Distance(i, iter->u, Sum_distance));
}
>>>>>>> origin/master
}
}
int main()
{
string infileImageTrain("C:\\Users\\lab309\\Desktop\\MINIST\\train-images.idx3-ubyte");
string infileLabTrain("C:\\Users\\lab309\\Desktop\\MINIST\\train-labels.idx1-ubyte");
Mat digitsUcharTrain;
Mat lableIntTrain;
MNIST mmt;
mmt.loadDigits(infileImageTrain, digitsUcharTrain);
mmt.loadLabels(infileLabTrain, lableIntTrain);
Mat digitsImageTrain;
digitsUcharTrain.convertTo(digitsImageTrain, CV_64FC1);
string infileImageTest("C:\\Users\\lab309\\Desktop\\MINIST\\t10k-images.idx3-ubyte");
string infileLabTest("C:\\Users\\lab309\\Desktop\\MINIST\\t10k-labels.idx1-ubyte");
Mat digitsUcharTest;
Mat lableIntTest;
mmt.loadDigits(infileImageTest, digitsUcharTest);
mmt.loadLabels(infileLabTest, lableIntTest);
Mat digitsImageTest;
digitsUcharTest.convertTo(digitsImageTest, CV_64FC1);
string file_name = "C:\\Users\\lab309\\Desktop\\MINIST\\pcaValue6000.xml";
//PCA pca(digitsImageTrain, cv::Mat(), CV_PCA_DATA_AS_ROW, low_dimension);
//savePCA(file_name.c_str(), pca);
PCA pca;
loadPCA(file_name.c_str(), pca);
Mat point = pca.project(digitsImageTrain);
//Mat pt1, pt2;
//point.row(0).copyTo(pt1);
//point.row(49).copyTo(pt2);
//double res = distance_node(pt1, pt2);
ifstream test("C:\\Users\\lab309\\Desktop\\MINIST\\knneartest600", ifstream::in);
ofstream result("C:\\Users\\lab309\\Desktop\\MINIST\\knneartest600-cost", ofstream::out);
vector<int> index;
vector<vector<int>> knn;
vector<vector<double>> knndistance;
int t;
double k;
vector<list<Node>> Adj;
Adj.assign(600, list<Node>());
index.resize(600);
knn.resize(600);
knndistance.resize(600);
for (int i = 0; i < 600; i++)
{
test >> index[i];
knn[i].resize(4);
knndistance[i].resize(4);
test >> t;
for (int j = 0; j < 3; j++)
{
test >> knn[i][j];
}
test >> k;
for (int j = 0; j < 3; j++)
{
test >> knndistance[i][j];
}
}
test.close();
bool flag1 = true, flag2 = true;
for (int i = 0; i < 600; i++)
{
for (int j = 0; j < 3; j++)
{
for (auto iter = Adj[i].begin(); iter != Adj[i].end(); iter++)
{
if (iter->u == knn[i][j])
flag2 = false;
}
if (flag2 == true)
{
Adj[i].push_back(Node(knn[i][j], knndistance[i][j]));
}
else
{
flag2 = true;
}
for (auto iter = Adj[knn[i][j]].begin(); iter != Adj[knn[i][j]].end(); iter++)
{
if (iter->u == i)
flag1 = false;
}
if (flag1 == true)
{
Adj[knn[i][j]].push_back(Node(i, knndistance[i][j]));
}
else
{
flag1 = true;
}
}
}
/*for (int i = 0; i < 50; i++){
<<<<<<< HEAD
for (auto iter = Adj[i].begin(); iter != Adj[i].end(); iter++)
cout <<iter->u <<" ";
cout << endl;
}*/
vector<Cost_Distance> heap_final;
Create_minheap(point, Adj, heap_final);
// min_Cost min_heap;
// Create_Min_Cost(point, Adj,min_heap);
Decrease_node(point, Adj, heap_final);
// cout << min_heap.size() << endl;
/*for (int i = 0; i < min_heap.size(); i++)
{
result << min_heap.top().node_i << " " << min_heap.top().node_j << " " << min_heap.top().cost_distance;
result << endl;
min_heap.pop();
}*/
/*for (int i = 0; i < 5; i++)
=======
for (auto iter = Adj[i].begin(); iter != Adj[i].end(); iter++)
cout <<iter->u <<" ";
cout << endl;
}*/
vector<Cost_Distance> heap_final;
Create_minheap(point, Adj,heap_final);
// min_Cost min_heap;
// Create_Min_Cost(point, Adj,min_heap);
Decrease_node(point, Adj, heap_final);
// cout << min_heap.size() << endl;
/*for (int i = 0; i < min_heap.size(); i++)
>>>>>>> origin/master
{
cout << min_heap.top().node_i << " " << min_heap.top().node_j << " " << min_heap.top().cost_distance;
cout << endl;
min_heap.pop();
}*/
/*for (int i = 0; i < 5; i++)
{
cout << min_heap.top().node_i << " " << min_heap.top().node_j << " " << min_heap.top().cost_distance;
cout << endl;
min_heap.pop();
}*/
//Dijstra(Adj, 0);
//Print(0, Adj.size());
system("pause");
return 0;
}