Пример #1
0
   def Solve(self, e):
       self.matPlotInit(self.plotParent, [],[])
       startTime = time.time()
       try:
           fileRead = tsp.consoleFileHandle(self.fileName)
           TSPtour = tsp.generateCities(fileRead)
           TSPtour = tsp.greedySearch(TSPtour)
       except:
           TSPtour = self.initialNodes 
           
       solveTime = int(self.solveTimeBox.GetValue())
 
       while time.time() < (startTime + int(solveTime)):
           TSPtour = tsp.greedyTwoOptSolver(TSPtour)
 
       ''' threading to handle unresponsive window  
       t = threading.Thread(target = self.solverThread, args=(TSPtour, startTime, solveTime))
       self.threads.append(t)
       t.start()
       t.join()
       '''
     
       self.coordGenerate(TSPtour)
       self.matPlotInit(self.plotParent, self.xs, self.ys)
       self.tourDistance = tsp.totalDistance(TSPtour)
       self.lengthText.SetLabel("Length: " + str(self.tourDistance))
       self.tourString = tsp.TourToString(TSPtour)
Пример #2
0
 def LoadFile(self, e):
     dialoge = wx.TextEntryDialog(None, '"File Name".tsp', 'Load File')
     if dialoge.ShowModal() == wx.ID_OK:
         self.fileName = dialoge.GetValue()
         fileRead = tsp.consoleFileHandle(self.fileName)
         
         problemName = fileRead[0][6:-1]
         comment = fileRead[1][9:-1]
         problemType = fileRead[4][18:-1]
         dimension = fileRead[3][10:-1]
         self.nameText.SetLabel("Name: " + problemName)
         self.commentText.SetLabel("Comment: " + comment)
         self.typeText.SetLabel("Type: " + problemType)
         self.sizeText.SetLabel("Size: " + dimension + " Nodes")
         self.timeText.SetLabel("Time: " + datetime.datetime.now().strftime("%H:%M:%S"))
         self.dateText.SetLabel("Date: " + datetime.datetime.now().strftime("%Y-%m-%d"))
         
         TSPtour = tsp.generateCities(fileRead)
         self.initialNodes = np.trim_zeros(TSPtour)
         TSPtour = tsp.greedySearch(TSPtour)
         self.coordGenerate(TSPtour)
         self.matPlotInit(self.plotParent, self.xs, self.ys)
         
     dialoge.Destroy()