-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile
76 lines (66 loc) · 1.93 KB
/
file
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
/*
static Edge clVisited(Agent agent, Graph g, Edge *move, int numMoves){
//mVisit = minimum Visits
//mWeight = minimum Weight
//lVisited = least Visited
int mVisit, mWeight = 0;
int numLVisited, numMWeight = 0;
int i = 0;
Edge *lVisited = malloc(sizeof(Edge) *numMoves);
assert(lVisited != NULL);
Edge *minWeight = NULL;
Edge turn;
if(numMoves > 1){
mVisit = agent->visits[move[0].w];
for(i = 0; i < numMoves; i++){
if(agent->visits[move[i].w] < mVisit){
mVisit = agent->visits[move[i].w];
}
}
//get all edges that are equal to min visits and add them
//to the array
for(i = 0, numLVisited = 0; i < numMoves; i++){
if(agent->visits[move[i].w] == mVisit){
lVisited[numLVisited] = move[i];
numLVisited++;
}
}
minWeight = malloc(sizeof(Edge) *numLVisited);
assert(minWeight != NULL);
//finding the minimum weight
if(numLVisited > 1){
mWeight = lVisited[0].weight;
for(i = 0; i < numLVisited; i++){
if(lVisited[i].weight < mWeight){
mWeight = lVisited[i].weight;;
}
}
//add it to the array
for(i = 0, numMWeight = 0; i < numLVisited; i++){
if(lVisited[i].weight == mWeight){
minWeight[numMWeight] = lVisited[i];
numMWeight++;
}
}
//choosing based on the smallest vertex
if(numMWeight > 1){
turn = minWeight[0];
for(i = 0; i < numMWeight; i++){
if(minWeight[i].w < turn.w){
turn = minWeight[i];
}
}
} else {
turn = minWeight[0];
}
} else {
turn = lVisited[0];
}
} else {
turn = move[0];
}
free(lVisited);
free(minWeight);
return turn;
}
*/