This commit is contained in:
Laurent Perron
2021-07-13 13:47:57 +02:00
parent 2287ed2b58
commit 700847b3ff
12 changed files with 46 additions and 46 deletions

View File

@@ -25,7 +25,7 @@ PARSER = argparse.ArgumentParser()
PARSER.add_argument(
'--solver', default='sat', help='Method used to solve: sat, mip.')
PARSER.add_argument(
'--output_proto',
'--output_proto_file',
default='',
help='Output file to write the cp_model proto to.')
@@ -105,7 +105,7 @@ def create_state_graph(items, max_capacity):
return states, transitions
def solve_cutting_stock_with_arc_flow_and_sat(output_proto):
def solve_cutting_stock_with_arc_flow_and_sat(output_proto_file):
"""Solve the cutting stock with arc-flow and the CP-SAT solver."""
items = regroup_and_count(DESIRED_LENGTHS)
print('Items:', items)
@@ -172,8 +172,8 @@ def solve_cutting_stock_with_arc_flow_and_sat(output_proto):
for i in range(len(objective_vars))))
# Output model proto to file.
if output_proto:
output_file = open(output_proto, 'w')
if output_proto_file:
output_file = open(output_proto_file, 'w')
output_file.write(str(model.Proto()))
output_file.close()
@@ -265,7 +265,7 @@ def solve_cutting_stock_with_arc_flow_and_mip():
def main(args):
"""Main function"""
if args.solver == 'sat':
solve_cutting_stock_with_arc_flow_and_sat(args.output_proto)
solve_cutting_stock_with_arc_flow_and_sat(args.output_proto_file)
else: # 'mip'
solve_cutting_stock_with_arc_flow_and_mip()

View File

@@ -32,7 +32,7 @@ PARSER = argparse.ArgumentParser()
PARSER.add_argument(
'--instance', default=1, type=int, help='Instance number (1..3).')
PARSER.add_argument(
'--output_proto',
'--output_proto_file',
default="",
help='Output file to write the cp_model'
'proto to.')

View File

@@ -33,7 +33,7 @@ from ortools.sat.python import cp_model
FLAGS = flags.FLAGS
flags.DEFINE_string('output_proto', '',
flags.DEFINE_string('output_proto_file', '',
'Output file to write the cp_model proto to.')
flags.DEFINE_string('params', 'num_search_workers:8,log_search_progress:true',
'Sat solver parameters.')
@@ -1933,9 +1933,9 @@ def bus_driver_scheduling(minimize_drivers, max_num_drivers):
model.Minimize(
cp_model.LinearExpr.ScalProd(delay_literals, delay_weights))
if not minimize_drivers and FLAGS.output_proto:
print('Writing proto to %s' % FLAGS.output_proto)
with open(FLAGS.output_proto, 'w') as text_file:
if not minimize_drivers and FLAGS.output_proto_file:
print('Writing proto to %s' % FLAGS.output_proto_file)
with open(FLAGS.output_proto_file, 'w') as text_file:
text_file.write(str(model))
# Solve model.

View File

@@ -24,7 +24,7 @@ from ortools.sat.python import cp_model
FLAGS = flags.FLAGS
flags.DEFINE_string('input', '', 'Input file to parse and solve.')
flags.DEFINE_string('output_proto', '',
flags.DEFINE_string('output_proto_file', '',
'Output file to write the cp_model proto to.')
flags.DEFINE_string('params', '', 'Sat solver parameters.')
flags.DEFINE_bool('use_interval_makespan', True,
@@ -316,7 +316,7 @@ def SolveRcpsp(problem, proto_file, params):
def main(_):
rcpsp_parser = pywraprcpsp.RcpspParser()
rcpsp_parser.ParseFile(FLAGS.input)
SolveRcpsp(rcpsp_parser.Problem(), FLAGS.output_proto, FLAGS.params)
SolveRcpsp(rcpsp_parser.Problem(), FLAGS.output_proto_file, FLAGS.params)
if __name__ == '__main__':

View File

@@ -21,7 +21,7 @@ from google.protobuf import text_format
FLAGS = flags.FLAGS
flags.DEFINE_string('output_proto', '',
flags.DEFINE_string('output_proto_file', '',
'Output file to write the cp_model proto to.')
flags.DEFINE_string('params', 'max_time_in_seconds:10.0',
'Sat solver parameters.')
@@ -184,7 +184,7 @@ def add_soft_sum_constraint(model, works, hard_min, soft_min, min_cost,
return cost_variables, cost_coefficients
def solve_shift_scheduling(params, output_proto):
def solve_shift_scheduling(params, output_proto_file):
"""Solves the shift scheduling problem."""
# Data
num_employees = 8
@@ -369,9 +369,9 @@ def solve_shift_scheduling(params, output_proto):
sum(obj_int_vars[i] * obj_int_coeffs[i]
for i in range(len(obj_int_vars))))
if output_proto:
print('Writing proto to %s' % output_proto)
with open(output_proto, 'w') as text_file:
if output_proto_file:
print('Writing proto to %s' % output_proto_file)
with open(output_proto_file, 'w') as text_file:
text_file.write(str(model))
# Solve the model.
@@ -419,7 +419,7 @@ def solve_shift_scheduling(params, output_proto):
def main(_):
solve_shift_scheduling(FLAGS.params, FLAGS.output_proto)
solve_shift_scheduling(FLAGS.params, FLAGS.output_proto_file)
if __name__ == '__main__':

View File

@@ -21,7 +21,7 @@ from ortools.sat.python import cp_model
# Command line arguments.
PARSER = argparse.ArgumentParser()
PARSER.add_argument(
'--output_proto',
'--output_proto_file',
default='',
help='Output file to write the cp_model'
'proto to.')
@@ -53,7 +53,7 @@ def main(args):
"""Solves a complex single machine jobshop scheduling problem."""
parameters = args.params
output_proto = args.output_proto
output_proto_file = args.output_proto_file
#----------------------------------------------------------------------------
# Data.
@@ -251,9 +251,9 @@ def main(args):
#----------------------------------------------------------------------------
# Write problem to file.
if output_proto:
print('Writing proto to %s' % output_proto)
with open(output_proto, 'w') as text_file:
if output_proto_file:
print('Writing proto to %s' % output_proto_file)
with open(output_proto_file, 'w') as text_file:
text_file.write(str(model))
#----------------------------------------------------------------------------