-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5,163 changed files
with
504,978 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
from Graph import DenseGraph | ||
import csv | ||
|
||
def performDijkstra(graph, src, dst): | ||
dist = {} | ||
path = {} | ||
Vertexes = [] | ||
for vertex in graph.vertexes: | ||
dist[vertex] = 99999999 | ||
Vertexes.append(vertex) | ||
dist[src] = 0 | ||
|
||
while len(Vertexes) != 0: | ||
minDist = 99999999 | ||
min_vertex = None | ||
for vertex in Vertexes: | ||
if dist[vertex] < minDist: | ||
min_vertex = vertex | ||
minDist = dist[vertex] | ||
if minDist == 99999999: | ||
break | ||
Vertexes.remove(min_vertex) | ||
|
||
neighbors, weights = graph.getNeighbors(min_vertex) | ||
for itr in range(len(neighbors)): | ||
if dist[neighbors[itr]] > dist[min_vertex] + weights[itr]: | ||
dist[neighbors[itr]] = dist[min_vertex] + weights[itr] | ||
path[neighbors[itr]] = min_vertex | ||
|
||
course = dst | ||
next = dst | ||
lstPath = [course] | ||
while next != src: | ||
next = path[next] | ||
lstPath = [next] + lstPath | ||
course = next + '->' + course | ||
|
||
return dist, path, course, lstPath | ||
|
||
def performAllDestinationDijkstra(graph, src): | ||
dist = {} | ||
path = {} | ||
routes = {} | ||
Vertexes = [] | ||
for vertex in graph.vertexes: | ||
dist[vertex] = 99999999 | ||
path[vertex] = None | ||
Vertexes.append(vertex) | ||
dist[src] = 0 | ||
|
||
while len(Vertexes) != 0: | ||
minDist = 99999999 | ||
min_vertex = None | ||
for vertex in Vertexes: | ||
if dist[vertex] < minDist: | ||
min_vertex = vertex | ||
minDist = dist[vertex] | ||
if minDist == 99999999: | ||
break | ||
Vertexes.remove(min_vertex) | ||
|
||
neighbors, weights = graph.getNeighbors(min_vertex) | ||
for itr in range(len(neighbors)): | ||
if dist[neighbors[itr]] > dist[min_vertex] + weights[itr]: | ||
dist[neighbors[itr]] = dist[min_vertex] + weights[itr] | ||
path[neighbors[itr]] = min_vertex | ||
|
||
# Return "routes" as a dictionary with a key of string vertex | ||
# Each value of the key should be a list of the route from the source as the input to the destination of the key which is a station | ||
for vertex in graph.vertexes: | ||
next = vertex | ||
temp = [next] | ||
while next != src: | ||
next = path[next] | ||
if next == None: | ||
temp = None | ||
break | ||
temp = [next] + temp | ||
routes[vertex] = temp | ||
|
||
return dist, path, routes | ||
|
||
if __name__ == "__main__": | ||
g = DenseGraph('Subway-Seoul.csv') | ||
|
||
while True: | ||
src = input('Source Station (예,''동두천'', type ''quit'' to quit): ') | ||
if src == 'quit': | ||
break | ||
elif src not in g.vertexes: | ||
print(src + " is not subway station, please try again") | ||
continue | ||
dst = input('Destination Station (예,''서울대입구''): ') | ||
if dst not in g.vertexes: | ||
print(dst + " is not subway station, please try again") | ||
continue | ||
|
||
dist, path, course, l = performDijkstra(g, src, dst) | ||
print("Path") | ||
print(course) | ||
print("Distance:") | ||
print(dist[dst]) | ||
print("list path") | ||
print(l) | ||
|
||
dist, path, course = performAllDestinationDijkstra(g, src) | ||
print("Path") | ||
print(course) | ||
print("Distance:") | ||
print(dist[dst]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
###################### DO NOT TOUCH THE BELOW CODE - IL-CHUL MOON ############# | ||
class Evaluator: | ||
def __init__(self,objGraph): | ||
self.objGraph = objGraph | ||
|
||
def evaluate(self,lstPlan,intRequestedAgent): | ||
dicVisit = {} | ||
|
||
if len(lstPlan) != intRequestedAgent: | ||
print("Plan Num Error : Requested : " + str(intRequestedAgent)+", Planned : "+str(len(lstPlan))) | ||
return -9999999 | ||
|
||
for i in range(len(self.objGraph.vertexes)): | ||
dicVisit[self.objGraph.vertexes[i]] = False | ||
|
||
for i in range(len(lstPlan)): | ||
for j in range(len(lstPlan[i])): | ||
strVisit = lstPlan[i][j] | ||
dicVisit[strVisit] = True | ||
|
||
lstKey = list(dicVisit.keys()) | ||
for i in range(len(dicVisit.keys())): | ||
strKey = lstKey[i] | ||
if dicVisit[strKey] == False: | ||
print("No visit : "+strKey) | ||
return -9999999 | ||
|
||
intCnt = 0 | ||
for i in range(len(lstPlan)): | ||
for j in range(len(lstPlan[i])): | ||
intCnt = intCnt + 1 | ||
if lstPlan[i][j] not in self.objGraph.edges.keys(): | ||
print("Invalid Node : " + str(lstPlan[i][j])) | ||
return -9999999 | ||
if j < len(lstPlan[i])-1: | ||
if lstPlan[i][j+1] not in self.objGraph.edges[lstPlan[i][j]].keys(): | ||
print("Invalid Edge : " + str(lstPlan[i][j]) + "," + str(lstPlan[i][j+1])) | ||
return -9999999 | ||
|
||
return 1000-intCnt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import random | ||
import csv | ||
|
||
class DenseGraph: | ||
vertexes = [] | ||
edges = {} | ||
|
||
def __init__(self,strFilename): | ||
self.vertexes = [] | ||
self.edges = {} | ||
|
||
csvfile = open(strFilename, 'r') | ||
reader = csv.reader(csvfile) | ||
|
||
for row in reader: | ||
if row[0] not in self.vertexes: | ||
self.addVertex(row[0]) | ||
self.addEdge(row[0], row[1], int(row[2])) | ||
|
||
csvfile.close() | ||
|
||
def addVertex(self, vertex): | ||
self.vertexes.append(vertex) | ||
self.edges[vertex] = {} | ||
|
||
def addEdge(self, src, dst, weight, directed=True): | ||
if directed == True: | ||
self.edges[src][dst] = weight | ||
else: | ||
self.edges[src][dst] = weight | ||
self.edges[dst][src] = weight | ||
|
||
def removeEdge(self,src,dst,directed=True): | ||
if directed == True: | ||
if dst in self.edges[src]: | ||
self.edges[src].pop(dst) | ||
else: | ||
if dst in self.edges[src]: | ||
self.edges[src].pop(dst) | ||
if src in self.edges[dst]: | ||
self.edges[dst].pop(src) | ||
|
||
def getNeighbors(self, vertex): | ||
retNeighbor = [] | ||
retWeight = [] | ||
for key in self.edges[vertex].keys(): | ||
retNeighbor.append(key) | ||
retWeight.append(self.edges[vertex][key]) | ||
return retNeighbor, retWeight | ||
|
||
def findComponent(self): | ||
checkVertex = {} | ||
for itr in range(len(self.vertexes)): | ||
checkVertex[self.vertexes[itr]] = False | ||
|
||
components = [] | ||
for itr in range(len(self.vertexes)): | ||
vertex = self.vertexes[itr] | ||
if checkVertex[vertex] == False: | ||
component = [] | ||
components.append(component) | ||
self.iterateNeighbors(vertex,checkVertex,component) | ||
return components | ||
|
||
def iterateNeighbors(self,vertex,checkVertex,component): | ||
checkVertex[vertex] = True | ||
component.append(vertex) | ||
for key in self.edges[vertex]: | ||
if checkVertex[key] == False: | ||
self.iterateNeighbors(key,checkVertex,component) | ||
|
||
def printComponent(self): | ||
components = self.findComponent() | ||
for itr in range(len(components)): | ||
print("Component "+str(itr)+" : "+str(len(components[itr]))) | ||
for vertex in components[itr]: | ||
print(vertex+",",end="") | ||
print() | ||
|
||
def getWeight(self, src, dst): | ||
return self.edges[src][dst] | ||
|
||
if __name__ == "__main__": | ||
g = DenseGraph('Subway-Seoul.csv') | ||
a, b =g.getNeighbors("장암") | ||
print(a) | ||
print(b) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import csv | ||
from googletrans import Translator | ||
import time | ||
|
||
translator = Translator() | ||
|
||
f = open('Subway-Seoul-ver-2.csv', 'r', encoding='euc-kr') | ||
f2 = open('Subway-Seoul-Eng-ver-2.csv', 'w', encoding='utf-8', newline='\n') | ||
|
||
reader = csv.reader(f) | ||
writer = csv.writer(f2) | ||
|
||
dic = {} | ||
for line in reader: | ||
print(line) | ||
|
||
if line[0] not in dic.keys(): | ||
dic[line[0]] = translator.translate(line[0]).text | ||
|
||
if line[1] not in dic.keys(): | ||
dic[line[1]] = translator.translate(line[1]).text | ||
|
||
newline = [dic[line[0]], dic[line[1]],int(line[2])] | ||
|
||
print(newline) | ||
writer.writerow(newline) | ||
|
||
time.sleep(3) | ||
|
||
f.close() | ||
f2.close() |
Oops, something went wrong.