예제 #1
0
 def undo(self):
     if len(self.state_stack) > 1:
         self.state_stack.pop()
         try:
             self.CurrentStateSnapshot = self.state_stack[-1]
         except IndexError:
             print "no more undo-operations stored!"
         self.figure.clf()
         self.graph = self.CurrentStateSnapshot.graph
         self.selected_nodes = self.CurrentStateSnapshot.selected_nodes
         self.digraph_on = self.CurrentStateSnapshot.digraph_on
         self.normalized = self.CurrentStateSnapshot.normalized
         self.GH = GraphHandler.GraphHandler(self.figure, self.name_dict,\
                                             self.CurrentStateSnapshot)
     else:
         print "no more undo-operations stored!"
예제 #2
0
def main():
    parser = argparse.ArgumentParser(description="run a genetic algorithm to solve the travelling salesman problem")
    req = parser.add_argument_group("required arguments")
    req.add_argument("-i", "--input_file", help="the input .tsp file", required=True)
    parser.add_argument("-o", "--output_file", help="optional output file for the bests and averages", default=None)
    parser.add_argument("-mx", "--max_gen", help="the maximum number of generations to run for (default=1000)",
                        type=int, default=1000)
    parser.add_argument("-ps", "--pop_size", help="the population size (default=50)", default=50, type=int)
    parser.add_argument("-cr", "--cross_rate", help="the crossover rate (default=1.0)", type=float, default=1.0)
    parser.add_argument("-mr", "--mut_rate", help="the mutation rate (default=0.1)", type=float, default=0.1)
    parser.add_argument("-cm", "--cross_mode", help="the mode of crossover, 0 for uox, 1 for pmx  (default=0)",
                        choices=[0, 1], type=int, default=0)
    args = parser.parse_args()

    try:
        fh = GraphHandler(args.input_file)
    except IOError as err:
        print(err)
        sys.exit(0)

    tsp = TSP(fh, args.output_file, args.max_gen, args.pop_size, args.cross_rate, args.mut_rate, args.cross_mode)
    tsp.genetic_algorithm()
예제 #3
0
    def __init__(self, QWidget, consoleOutput, parent=None):
        QtGui.QWidget.__init__(self, parent)
        #Unlike better languages, you have to manually call the super constructor
        super(CaptureArea, self).__init__()

        #this is just used to print to console output
        self.consoleOut = consoleOutput

        #This is auto generated code. Notice the names
        self.gridLayout_2 = QtGui.QGridLayout(QWidget)
        self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
        self.captureArea = QtGui.QTabWidget(QWidget)
        self.captureArea.setObjectName(_fromUtf8("captureArea"))

        #Stores the 4 camera threads
        self.cvObjectLists = []

        #The graph handler object
        self.graphHandler = GraphHandler(self, consoleOutput)

        #Each tabs has 3 parts, they are lists so the user can make unlimited tabs
        self.tabs = []
        self.gridLayouts = []
        self.widgets = []

        self.captureArea.insertTab(3, self.graphHandler, "plot")

        #after creating all the tabs for capture area, add it to the layout. This is the whole otter layout.
        self.gridLayout_2.addWidget(self.captureArea, 0, 0, 1, 1)

        self.connect(self.gridLayout_2, QtCore.SIGNAL("resized()"),
                     self.onResize)

        self.newTab()
        self.newTab()
        self.newTab()
예제 #4
0
n2 = GS.Node(0, 9, 1)  #B
n3 = GS.Node(10, 0, 1)  #C
n4 = GS.Node(10, 10, 1)  #D

# These should never be here and are only for debug purpose

e1 = GS.Edge(n1, n2)  #AB
e2 = GS.Edge(n1, n3)  #AC
e3 = GS.Edge(n2, n4)  #BD
e4 = GS.Edge(n3, n4)  #CD
e5 = GS.Edge(n1, n4)

start_nodes = [n1, n2, n3, n4]
start_edges = []  #[e1, e2, e3, e4, e5]

GH = gh.GraphHandler()

for node in start_nodes:
    GH.addNode(node)

for edge in start_edges:
    GH.addEdgeObj(edge)

valueX = ''
valueY = ''

while valueX != 'exit' or valueY != 'exit':
    valueX = float(input("Value X of new node: "))
    valueY = float(input("Value Y of new node: "))
    if isinstance(valueX,
                  (int, long, float)) and isinstance(valueY,
예제 #5
0
import GraphHandler as g
import MessageHandler as m

exit = False
baudrate = 15500
timeout = None
port_name = "COM4"
Gui = g.GraphHandler()
MsgHandler = m.MessageHandler(port_name, baudrate_=baudrate, timeout_=timeout)
MsgHandler.StartCommunication()
while (not Gui.exit):
    for i in range(3 * g.NUMBER_OF_KINETIS):
        msg = MsgHandler.ReadFrame()
        MsgHandler.ManageMessage(msg, len(msg))
    list_of_positions = MsgHandler.GetPositions()
    Gui.UpdateBoards(list_of_positions)

MsgHandler.EndCommunication()
예제 #6
0
                        type=int,
                        help='set multicast port')
    parser.add_argument('-ip',
                        '--set_stream_ip',
                        action='store',
                        default='224.2.10.100',
                        help='set multicast ip address group')

    # for testing purposes
    parser.add_argument(
        '-om',
        '--set_output_mode',
        action='store',
        default='print',
        choices=['print', 'store', 'graph'],
        help=
        'set multicast output mode, print to terminal, store to file, or graph (requires ui) (default="print")'
    )

    args = parser.parse_args()

    mcast = multicast(args.set_stream_ip, args.set_stream_port,
                      args.set_stream_type, args.set_output_mode)

    if args.set_output_mode in ['store', 'print']:
        mcast.output()
    else:
        tsg = gh.GraphHandler(mcast.generator())

        # tsg = gh.TimeSeriesGraph(stream().read())
예제 #7
0
    def __init__(self, source_path, dest_path):
        self.state_stack = []  #stores snapshots of current states
        self.max_stored_states = 10  #defines the maximum number of possible undo actions

        work_name = os.path.basename(
            source_path)  #name of the directory we are working in
        self.source_path = source_path  #path to the working directory
        if dest_path == None:
            dest_path = source_path  #if specified: path to the directory files will be saved to

        self.name_dict = {
            'work_name':
            work_name,  #store names in dictionary to make things cleaner
            'source_path': source_path,
            'dest_path': dest_path
        }

        self.graph = None  #try to load the graph object
        for f in os.listdir(self.name_dict['source_path']
                            ):  #look for a file that ends with '_red1.gpickle'
            if f.endswith(
                    '_red1.gpickle'
            ):  #this corresponds to a graph which has some redundant nodes left
                self.graph = load(join(self.name_dict['source_path'], f))
        if self.graph == None:  #if no suitable file is found, print an error message
            print 'No corresponding .gpickle-file found!'\
            +' (looking for _red1.gpickle)\nClosing the GUI.'
            printHelp()  #print the help message and exit the GUI
            sys.exit()

        self.selected_nodes = {
        }  #stores the keys of the currently selected nodes
        self.mode_list = [
        ]  #list of currently switched on modes which will be displayed at the top of the figure

        #state flags
        self.select_on = False  #node selection mode on?
        self.digraph_on = False  #is the graph already a digraph?
        self.normalized = False  #has the graph already been streamlined? (redundant nodes removed)
        self.shift_on = False  #is the shift key pressed? (ugly but working modifier handling...)

        #figure initialization
        self.dpi = 100  #resolution, increase for super crowded graphs
        self.figsize = (
            12, 12
        )  #size of the figure, tinker with this if the displayed figure does not fit your monitor
        self.figure = plt.figure(dpi=self.dpi, figsize=self.figsize)

        #initialize state stack and mode
        self.CurrentStateSnapshot = StateSnapshot(
            self.graph,  #take an initial snapshot and store it
            self.selected_nodes,
            self.digraph_on,
            self.normalized)
        self.update_state_stack()

        self.GH = GraphHandler.GraphHandler(
            self.figure,
            self.name_dict,  #initialize the graph handler
            self.CurrentStateSnapshot)

        self.update_mode("Image: " + self.name_dict['work_name'],
                         'add')  #update the display at the top of the figure
        self.edit_loop()  #start the main interaction loop