Skip to content

Commit

Permalink
Command line arguments for sample
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartJKlein committed Dec 15, 2017
1 parent 874b368 commit bc95618
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
18 changes: 16 additions & 2 deletions sample/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@
import colors as CLR
import settings
from classes import Gates, Netlist, Solution
import sys

if len(sys.argv) > 1:
if not sys.argv[1].isdigit() or not sys.argv[2].isdigit() or int(sys.argv[1]) > 2 or int(sys.argv[2]) > 6:
print("Usage: python sample gates-number netlist-number")
exit()
else:
settings.FILE_GATES = int(sys.argv[1])
settings.FILE_NETLIST = int(sys.argv[2])

if settings.FILE_GATES > 1:
settings.BOARD_HEIGHT = 17
else:
settings.BOARD_HEIGHT = 13

# Print program settings
if settings.SHOW_SETTINGS:
if settings.PRINT_SETTINGS:
print("")
print("Using netlist: "
+ CLR.GREEN
Expand All @@ -38,7 +52,7 @@
netlist = Netlist(settings.FILE_NETLIST)

# Print inputted netlist
if settings.SHOW_NETLIST:
if settings.PRINT_NETLIST:
print("Netlist: " + CLR.GREEN + str(netlist.list) + CLR.DEFAULT)
print("--------------------------------------------------------")

Expand Down
33 changes: 16 additions & 17 deletions sample/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,6 @@ def draw_DIJKSTRA(self, board):
return True

else:
#if settings.SHOW_EACH_RESULT
#print("Path " + str(self.label) + " ERROR. Could not be drawn.")
return False

def get_coords(self, axes):
Expand Down Expand Up @@ -992,7 +990,7 @@ def run(self, gates, netlist):
self.scores.append(score)

# Show result of the board
if settings.SHOW_EACH_RESULT:
if settings.PRINT_EACH_RESULT:
sys.stdout.flush()
print("Board "
+ CLR.YELLOW + "#"
Expand Down Expand Up @@ -1072,20 +1070,21 @@ def run(self, gates, netlist):
board.redraw_random_path()

# Print best result of this run
print("")
print("------------ BEST RESULT out of "
+ str(self.boards)
+ " boards ---------------")

print("Paths drawn: "
+ CLR.GREEN
+ str(self.best_result)
+ "%" + CLR.DEFAULT)

print("Score: "
+ CLR.GREEN
+ str(self.best_score)
+ CLR.DEFAULT)
if settings.PRINT_BEST_RESULT:
print("")
print("------------ BEST RESULT out of "
+ str(self.boards)
+ " boards ---------------")

print("Paths drawn: "
+ CLR.GREEN
+ str(self.best_result)
+ "%" + CLR.DEFAULT)

print("Score: "
+ CLR.GREEN
+ str(self.best_score)
+ CLR.DEFAULT)

# Close the visualisation
if settings.PLOT_PROGRESS:
Expand Down
28 changes: 12 additions & 16 deletions sample/settings.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
"""Settings to be used by the classes.py."""

# Return result and score
# Returns
RETURN_RESULTS = False

# Info at start of the program
SHOW_SETTINGS = False
SHOW_NETLIST = False

# Animated visualisation
# Plots
PLOT_PROGRESS = True

# Show / plot results
PLOT_BEST = False
PLOT_SCORES = False
PLOT_RESULTS = False
SHOW_EACH_RESULT = False
SHOW_EACH_PLOT = False
SHOW_BEST_RESULT = False

# Prints
PRINT_SETTINGS = False
PRINT_NETLIST = False
PRINT_BEST_RESULT = False
PRINT_EACH_RESULT = False

# Program settings
FILE_NETLIST = 1
FILE_GATES = 1

BOARD_WIDTH = 18
BOARD_HEIGHT = 13
BOARD_DEPTH = 8

FILE_NETLIST = 1
FILE_GATES = 1

MAX_NO_IMPROVE = 5

# Pathfinding
PATH_ALGORITHM = "ASTAR" # ASTAR / DIJKSTRA

# Heuristics for A*
COST_PASSING_GATE = 1000
STEP_COST_PASSING_GATE = 100

Expand Down

0 comments on commit bc95618

Please sign in to comment.