-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.h
133 lines (113 loc) · 3.22 KB
/
map.h
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
//
// map.h
// Flow
//
// Created by Ziyun Kong on 12/11/13.
// Copyright (c) 2013 Ziyun Kong. All rights reserved.
//
#ifndef __Flow__map__
#define __Flow__map__
#include <iostream>
#include <vector>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <pthread.h>
#include <omp.h>
#define EMPTY NULL
typedef std::map<std::pair<int, int>, std::string> MapInfo;
struct PointT {
int x;
int y;
PointT(){}
PointT(const PointT &p_):x(p_.x), y(p_.y){}
PointT(int x_, int y_):x(x_), y(y_){}
};
struct DotPairT {
std::string color;
PointT loc1;
PointT loc2;
DotPairT(std::string color_, PointT p1_, PointT p2_)
:color(color_), loc1(p1_), loc2(p2_){}
};
struct DotT{
std::string color;
PointT loc;
DotT(){}
DotT(std::string c_, PointT l_):color(c_), loc(l_){}
DotT(DotT &p_):color(p_.color), loc(p_.loc){}
};
struct PathNodeT {
PathNodeT* prev;
PointT cur;
std::map<std::pair<int, int>, std::string> pathMap;
PathNodeT(){}
PathNodeT(PathNodeT* prev_, PointT cur_, std::map<std::pair<int, int>, std::string> map_): prev(prev_), cur(cur_), pathMap(map_){}
};
struct mapInfoT {
std::set<std::pair<int, int> > uniqueMap;
std::vector<DotT> colorDotMap;
};
struct intNodeT{
int curLoc;
std::vector<int> path;
intNodeT(int l_, std::vector<int> p_):curLoc(l_), path(p_){}
};
struct pthreadInput {
int tid;
std::map<std::string, DotPairT*>::iterator map_it;
MapInfo mapInfo;
pthreadInput(int t_, std::map<std::string, DotPairT*>::iterator i_, MapInfo m_): tid(t_), map_it(i_), mapInfo(m_){}
};
class Map{
int size;
bool found;
omp_lock_t lockFound;
bool *threadUsing;
std::vector<DotPairT*> Dots;
std::map<std::string, DotPairT*> DotsMap;
std::string **FlowMap;
std::vector<std::string> colorList;
// std::set<std::pair<int, int> > currentMap;
// std::set<std::pair<int, int> > prevMap;
// mapInfoT initMap;
//std::map<std::string, std::vector<MapInfo> > possiblePaths;
std::map<std::string, std::vector<PathNodeT*>*> possiblePaths;
std::map<std::pair<int, int>, std::string> initMapInfo;
MapInfo* solution;
std::vector<int> initIntMap;
//void generateIntPathsForPair(std::string);
void generatePathsForPair(std::string);
std::vector<MapInfo> analyzePathsHelper(std::map<std::string, DotPairT*>::iterator, MapInfo, bool& found);
void* analyzeDotPair(void* input);
bool isCollide(PathNodeT*, PointT, std::map<std::pair<int, int>, std::string>);
void combTosep(int comb, int &x, int &y){
x = comb % size;
y = comb / size;
return;
}
void sepTocomb(int &comb, int x, int y){
comb = x + y * size;
return;
}
int getNextId();
public:
Map(){found = false; solution = NULL;}
Map(int size_):size(size_){found = false; solution = NULL;}
//std::map<std::string, std::vector<PathNodeT*>*> getPaths(){return possiblePaths;}
void printPath(std::string);
void setThreadNum(int a){
threadUsing = new bool[a];
for (int i = 0; i < a; ++i)
threadUsing[i] = false;
}
void setDot(std::string color, PointT p1, PointT p2);
void setMap();
void analyzeFlowMap();
MapInfo *getMap(){return solution;}
void generatePaths();
std::vector<MapInfo> analyzePaths();
};
#endif /* defined(__Flow__map__) */