Example #1
0
def main():
    input_filename, output_filename = sys.argv[1], sys.argv[2]

    input_file = open(input_filename)
    output_file = open(output_filename, "w")

    F = Reader.integer_list_line(input_file)
    T = Reader.integer_list_line(input_file)
    p = Reader.integer_list_line(input_file)

    c = {}
    for i in machines:
        c_line = Reader.integer_list_line(input_file)
        for j in products:
            c[i, j] = c_line[j - 1]

    t = {}
    for i in machines:
        t_line = Reader.integer_list_line(input_file)
        for j in products:
            t[i, j] = t_line[j - 1]

    solver = ProductionProblem()

    solution = solver.solve(F, T, p, c, t)

    if isinstance(solution, SolutionNotFound):
        Writer.integer(output_file, -1)
    elif isinstance(solution, SolutionFound):
        Writer.integer(output_file, solution.cost)
        for i in machines:
            Writer.integer_list_line(output_file, solution.X[i - 1])
Example #2
0
def main():
    # Input
    input_filename, output_filename = sys.argv[1], sys.argv[2]

    input_file = open(input_filename)
    output_file = open(output_filename, "w")

    num_of_customers, num_of_products = Reader.integer_list_line(input_file)
    customers = {}

    for i in range(1, num_of_customers + 1):
        numbers = Reader.integer_list_line(input_file)
        customer = CustomerDemand(i, numbers[0], numbers[1], numbers[2:])
        customers[i] = customer

    review_demands = Reader.integer_list_line(input_file)
    review_demands_dict = {
        i + 1: demand
        for i, demand in enumerate(review_demands)
    }
    # Solver
    solver = Problem()
    solution = solver.solve(customers, review_demands_dict, num_of_products,
                            num_of_customers)

    # Output
    if isinstance(solution, SolutionNotFound):
        Writer.integer(output_file, -1)
    else:
        for i in range(1, 1 + num_of_customers):
            customer_assignment = solution.assignments[i]
            Writer.integer_list_line(output_file, customer_assignment.products)

    input_file.close()
    output_file.close()
Example #3
0
def main():
    input_filename, output_filename = sys.argv[1], sys.argv[2]

    input_file = open(input_filename)
    output_file = open(output_filename, "w")

    # Inputs
    n = Reader.single_integer(input_file)

    tasks = []
    for i in range(1, n + 1):
        task = Reader.integer_list_line(input_file)
        tasks.append(task)

    # Solver
    solution = solve(tasks)

    # Outputs
    if not solution.is_feasible():
        Writer.integer(output_file, -1)
    else:
        for i in range(1, n + 1):
            print(solution[i])
            Writer.integer(output_file, solution[i])

    input_file.close()
    output_file.close()
Example #4
0
def main():
    input_filename, output_filename = sys.argv[1], sys.argv[2]

    input_file = open(input_filename)
    output_file = open(output_filename, "w")

    # Inputs
    cardinality, width, height = Reader.integer_list_line(input_file)
    stripes = Stripes(cardinality)

    for i in range(1, cardinality + 1):
        image = Reader.integer_list_line(input_file)
        stripes.add(Stripe(i - 1, height, width, image))

    # Solver
    solver = ProblemSolver()
    solution = solver.solve(stripes)

    # Outputs
    print("*" * 100)
    print(solution.path)
    Writer.integer_list_line(output_file, solution.path)

    input_file.close()
    output_file.close()
Example #5
0
def main():
    input_filename, output_filename = sys.argv[1], sys.argv[2]

    input_file = open(input_filename)
    output_file = open(output_filename, "w")

    demands = Reader.integer_list_line(input_file)

    solver = CallCenterSolver(demands)

    Writer.integer(output_file, solver.optimum)
    Writer.integer_list_line(output_file, solver.hour_schedule)
Example #6
0
def main():
    print(sys.argv)
    input_filename, output_filename = sys.argv[1], sys.argv[2]

    input_file = open(input_filename)
    output_file = open(output_filename, "w")

    # Inputs
    hometown = Reader.string_line(input_file)

    types = (str, str, int, int)
    flights = Reader.multi_types_multi_lines(input_file, types)

    # Solver
    solver = AirTicketSolver()
    solution = solver.solve(hometown, flights)

    # Outputs
    Writer.integer(output_file, solution.cost)
    Writer.list_line(output_file, solution.plan)

    input_file.close()
    output_file.close()
Example #7
0
def main():
    # Input
    input_filename, output_filename = sys.argv[1], sys.argv[2]

    input_file = open(input_filename)
    output_file = open(output_filename, "w")

    num_of_objects, num_of_frames = Reader.integer_list_line(input_file)

    frames = []
    for _ in range(num_of_frames):
        frame = Reader.integer_list_line(input_file)
        frames.append(frame)

    # Problem Solution
    problem = MultipleFramesProblem()
    solution = problem.solve(frames)

    # Output
    for assignment in solution.assignments:
        Writer.integer_list_line(output_file, assignment)

    input_file.close()
    output_file.close()
Example #8
0
    def __init__(self, infile, outfile=None, filters=None, invert=False):
        # Methods to add to Reader
        def get_filter(self):
            return self._samp_filter

        def set_filter(self, filt):
            self._samp_filter = filt
            if filt:
                self.samples = [
                    val for idx, val in enumerate(self.samples)
                    if idx not in set(filt)
                ]

        def filter_samples(fn):
            """Decorator function to filter sample parameter"""
            def filt(self, samples, *args):
                samples = [
                    val for idx, val in enumerate(samples)
                    if idx not in set(self.sample_filter)
                ]
                return fn(self, samples, *args)

            return filt

        # Add property to Reader for filter list
        Reader.sample_filter = property(get_filter, set_filter)
        Reader._samp_filter = []
        # Modify Reader._parse_samples to filter samples
        self._orig_parse_samples = Reader._parse_samples
        Reader._parse_samples = filter_samples(Reader._parse_samples)
        self.parser = Reader(filename=infile)
        # Store initial samples and indices
        self.samples = self.parser.samples
        self.smp_idx = dict([(v, k) for k, v in enumerate(self.samples)])
        # Properties for filter/writer
        self.outfile = outfile
        self.invert = invert
        self.filters = filters
        if filters is not None:
            self.set_filters()
            self.write()