def main(argv):
    input_file = argv[0]
    grid, max_turns, drones, warehouses, orders = parse_input(input_file)
    commands = list()
    drone_map = {drone: 0 for drone in drones}
    for order in orders:
        drone = find_min(drone_map, max_turns)
        temp_commands = list()
        if order.total_weight > drone.capacity:
            continue

        route = drone.find_order_route(order)
        time = 0
        for warehouse in route:
            distance = warehouse.distance(drone.position)
            item_map = route[warehouse]
            for item, amount in item_map.items():
                temp_commands.append("%d L %d %d %d" % (drone.index, warehouse.index, item, amount))
            time += distance + len(item_map)
            drone.position = warehouse.position

        distance = order.position.distance(drone.position)
        for product, amount in order.amounts.items():
            temp_commands.append("%d D %d %d %d" % (drone.index, order.index, product, amount))

        time += distance + len(order.amounts.items())
        if(time > max_turns - drone_map[drone]):
            continue
        else:
            commands += temp_commands
    print(len(commands))
    for cmd in commands:
        print(cmd)
Beispiel #2
0
	def create(self):
		print("Create Invoked")
		print(self.axiom)
		proc_axiom = pr.parse_input(self.map_input, self.axiom, self.depth, self.variables)
		print(self.dist)
		print(proc_axiom)
		self.draw_axiom(proc_axiom, self.ang, self.dist)
Beispiel #3
0
def executor():
    arguments = parse_input()

    tables = DbHandler()

    service_args_handler(arguments, tables)

    source = source_path_handler(arguments)

    parsed_data = parse_csv(source)

    create_struct(parsed_data, tables, arguments)
Beispiel #4
0
 def lineReceived(self, line):
     '''
     Called everytime an avatar sends a line
     This is where logging and output is done
     '''
     command = line.strip()
     self.log_stash('command', command)
     if command == 'exit':
         self.transport.loseConnection()
         return
     output = parse_input(command)
     self.terminal.write(output)
     self.showPrompt()
def parse():
    # get the pseudocode from the requests
    pseudocode = request.args.get("input")

    is_error = False

    # try to parse_input, if there is an exception, set is_error to True
    try:
        currents[session["id"]] = parse_input(pseudocode,
                                              currents[session["id"]])
    except:
        is_error = True

    # return a JSON for the AJAX request
    return jsonify(isError=is_error,
                   indentLevel=currents[session["id"]].level,
                   code=str(roots[session["id"]]))
Beispiel #6
0
    def run(self):
        print("Input task started")
        print("[q = 1,2,3,4,5,6,7,8 or]\n[q0 = pi/2]\n\n")

        #Thread is daemonic, so this loop will only stop when the main thread is stopped
        while (True):
            try:
                #Waits for an input.
                #If the input is joint angles, create a trajectory and add it to the queue
                q_f = parser.parse_input()

                trajectory = Trajectory(q_f)

                if trajectory.is_valid():
                    self.trajectory_queue.put(trajectory)
                else:
                    print("Trajectory not valid")
                    #trajectory_queue.join()
                    #self.master_board.terminate()

                    #Should stop the robot where it is, but not shut down the master board

                #If parser detects one of these specified inputs, the specified action will happen
            except ParseError as e:
                if e.msg == "Exit":
                    self.master_board_task.terminate()
                if e.msg == "Position":
                    self.master_board_task.set_print()
                if e.msg == "Calibrate":
                    if self.generated == False:
                        print(
                            "Calibration initated, type c to go to next point")
                        calibration_generator = config.Calibration_parameters(
                            0)
                        self.generated = True

                    else:
                        try:
                            trajectory = Trajectory(
                                next(calibration_generator))
                            self.trajectory_queue.put(trajectory)
                        except StopIteration:
                            print("Calibration Done")
                            self.generated = False
Beispiel #7
0
    plt.rc('axes', labelsize=8)

    gs = plt.GridSpec(1, 1)
    gs.update(hspace=0.0)
    gs.update(wspace=0.0)

    axs = []
    axs.append(plt.subplot(gs[0, 0]))

    for ax in axs:
        ax.minorticks_on()

    #--------------------------------------------------
    # command line driven version

    conf, fdir, args = parse_input()

    fdir += '/'
    print("plotting {}".format(fdir))

    #fname_P = "particles"
    fname_P = "test-prtcls"

    # if lap is defined, only process that one individual round
    if not (args.lap == None):
        info = {}
        info['lap'] = args.lap
        info['fdir'] = fdir
        #info['particle_file'] = fdir+'restart/'+fname_P
        info['particle_file'] = fdir + fname_P
def main(input_file):
    B, L, D, N, T, M, BS, LB = parse_input(input_file)
    LBS = library_score(LB,BS)
    print('blah')
def main(argv):
    input_file = argv[0]
    grid, n_turns, max_payload, drones, warehouses, orders = parse_input(input_file)
    do_dummy_route(grid, n_turns, max_payload, drones, warehouses, orders)
Beispiel #10
0
def main():
    inp = "fsa.txt"
    out = "result.txt"
    output = open(out, "w")
    data = parser.parse_input(inp, out)
    machine = FSA.FSA()
    incomplite = False

    # Filling states and transitions

    for state in data[0]:
        machine.add_state(state)

    for transition in data[1]:
        machine.add_transition(transition)

    # If initial state does not defined in input the error
    if machine.get_state(data[2]) == -1:
        error = "E1: A state '" + data[2] + "' is not in set of states"
        output.write("Error:\n" + error)
        output.close()
        exit(0)
    else:
        machine.initial = machine.get_state(data[2])

    # If final state not defined the warning3
    if len(data[3]) == 0:
        machine.warnings.append(W1)
    else:
        # If final state does not exist then error
        for fin_state in data[3]:
            state = machine.get_state(fin_state)
            if state == -1:
                error = "E1: A state '" + fin_state + "' is not in set of states"
                output.write("Error:\n" + error)
                output.close()
                exit(0)
            else:
                machine.final.append(state)
    # Parsing transitions and what they will do
    for path in data[4]:
        elements = path.split(">")
        # Checking for existing
        if (machine.get_state(elements[0]) == -1):
            error = "E1: A state '" + elements[0] + "' is not in set of states"
            output.write("Error:\n" + error)
            output.close()
            exit(0)
        elif (machine.get_state(elements[2]) == -1):
            error = "E1: A state '" + elements[0] + "' is not in set of states"
            output.write("Error:\n" + error)
            output.close()
            exit(0)

        else:
            state_left = machine.get_state(elements[0])
            state_right = machine.get_state(elements[2])
            # If transition does not defined then error
            if (machine.get_transition(elements[1]) == -1):
                error = "E3: A transition '" + elements[
                    1] + "' is not represented in the alphabet"
                output.write("Error:\n" + error)
                output.close()
                exit(0)
            else:
                trans = machine.get_transition(elements[1])
                trans.from_state = state_left
                trans.to_state = state_right
                state_left.commands[elements[1]] = state_right
                if (state_right.state != state_left.state):
                    state_left.outputs.append(state_right)
                    state_right.inputs.append(state_left)
                    state_left.outputs = list(set(state_left.outputs))
                    state_right.inputs = list(set(state_right.inputs))

    # Loop to handle possible error and warnings
    for state in machine.states.values():

        if (len(state.inputs) == 0) and (len(
                state.outputs) == 0) and (len(machine.states.keys()) > 1):
            error = E2
            output.write("Error:\n" + error)
            output.close()
            exit(0)
        if len(state.commands.keys()) < len(machine.transitions):
            incomplite = True

        if (len(state.inputs) == 0) and (len(machine.states.keys()) != 1):
            machine.warnings.append(W2)

        if len(state.commands.keys()) != len(list(set(state.commands.keys()))):
            machine.warnings.append(W3)

    # Printing finite results
    machine.warnings = list(set(machine.warnings))
    machine.warnings.sort()
    if incomplite:
        output.write(R2)
        if len(machine.warnings) > 0:
            output.write("\nWarning:")
            for i in machine.warnings:
                output.write("\n" + i)
            output.close()
            exit(0)
    else:
        output.write(R1)
        if len(machine.warnings) > 0:
            output.write("\nWarning:")
            for i in machine.warnings:
                output.write("\n" + i)
            output.close()
            exit(0)
Beispiel #11
0
from parser import parse_input
from algs.hill_climbing import hill_climbing

if __name__ == "__main__":
    state = parse_input('input/input.txt')
    state.genInitialSolution()
    state.print()

    NUM_ITS = 10

    ####################
    # Hill Climbing
    ####################

    state = hill_climbing(state, NUM_ITS)
    state.print()
Beispiel #12
0
    def run(self):
        # Priority settings for "InputTask" process
        print(
            f"Input task started with pid: {os.getpid()} and priority: {os.sched_getparam(os.getpid())}"
        )

        pid = os.getpid()
        sched = os.SCHED_FIFO
        param = os.sched_param(50)

        os.sched_setscheduler(pid, sched, param)

        print(
            f"Input task with pid: {os.getpid()} changed to priority: {os.sched_getparam(os.getpid())}\n"
        )

        sys.stdin = os.fdopen(self.standard_input)

        print()
        print(f"Robot is currently in {self._mode} mode")

        while (self._running):
            try:
                input_params, input_message = parser.parse_input(">")
            except EOFError:
                self.terminate()
                continue

            if input_message == "Angles":
                if self._mode == "Idle":
                    trajectory = trj.Trajectory(input_params)

                    if trajectory.is_valid():
                        self.trajectory_queue.put(trajectory)
                else:
                    print(
                        "Robot is not in idle mode. Send it to idle by typing >Idle"
                    )

            elif input_message == "Coordinates":
                if self._mode == "Walk":
                    with self.shared_position.get_lock():
                        current_position = self.shared_position[:]

                    joint_params = kinematics.simple_walk_controller(
                        input_params, current_position)

                    if None in joint_params:
                        continue

                    #print(f"Going to : {joint_params} [RAD]")
                    #print(f"Joint angles : {np.degrees(joint_params)} [deg]")

                    trajectory = trj.Trajectory(joint_params)

                    if trajectory.is_valid():
                        self.trajectory_queue.put(trajectory)
                else:
                    print("Robot is not in walking mode. Type >Walk")
            else:
                self.handle_input(input_message)

        sys.stdin.close()
Beispiel #13
0
    def get_args(self):
        conf, fdir, args = parse_input()

        return conf, fdir, args
Beispiel #14
0
import parser
import Serial_Approach

FILE_NAMES = [
    "a_example.txt", "b_read_on.txt", "c_incunabula.txt",
    "e_so_many_books.txt", "f_libraries_of_the_world.txt",
    "d_tough_choices.txt"
]
OUTPUT_FILES = [
    "submission_a.txt", "submission_b.txt", "submission_c.txt",
    "submission_e.txt", "submission_f.txt", "submission_d.txt"
]

for name, out in zip(FILE_NAMES, OUTPUT_FILES):
    f = open(name, "r")
    input = parser.parse_input(f)
    libs = parser.get_libraries(input)
    scores = parser.get_scores(input)
    deadline = parser.get_deadline(input)

    lib_order = Serial_Approach.libraryOrder(libs, deadline, scores)
    parser.output(lib_order, out)
Beispiel #15
0
        key=lambda x: x[1][0])  # sort by largest combined sum
    return sorted_var_counts


def get_most_seen_sign(whole_p):
    tup = whole_p[1]
    positive = tup[1]
    negative = tup[0] - positive
    return positive > negative


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('cnf_file')
    args = parser.parse_args()
    variables, clauses = parse_input(args.cnf_file)
    t0 = time.time()
    sorted_var_counts = get_var_counts(clauses)
    literal_to_clauses = get_literal_to_clauses(clauses)
    clause_to_unassigned = get_clause_number_of_unassigned(clauses)

    beginning_clauses = clauses
    unknown_clauses_indexes = set(range(len(beginning_clauses)))
    P = variables.pop()
    variables.add(P)
    sign = True
    # set limit to 2000 since all these cnfs have at most ~1700 variables.
    sys.setrecursionlimit(2000)
    getBack = dpll(variables, unknown_clauses_indexes, {}, sorted_var_counts,
                   literal_to_clauses, clause_to_unassigned, None, None)