fix #2656
This commit is contained in:
@@ -94,7 +94,7 @@
|
||||
"PARSER.add_argument(\n",
|
||||
" '--solver', default='sat', help='Method used to solve: sat, mip.')\n",
|
||||
"PARSER.add_argument(\n",
|
||||
" '--output_proto',\n",
|
||||
" '--output_proto_file',\n",
|
||||
" default='',\n",
|
||||
" help='Output file to write the cp_model proto to.')\n",
|
||||
"\n",
|
||||
@@ -174,7 +174,7 @@
|
||||
" return states, transitions\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def solve_cutting_stock_with_arc_flow_and_sat(output_proto):\n",
|
||||
"def solve_cutting_stock_with_arc_flow_and_sat(output_proto_file):\n",
|
||||
" \"\"\"Solve the cutting stock with arc-flow and the CP-SAT solver.\"\"\"\n",
|
||||
" items = regroup_and_count(DESIRED_LENGTHS)\n",
|
||||
" print('Items:', items)\n",
|
||||
@@ -241,8 +241,8 @@
|
||||
" for i in range(len(objective_vars))))\n",
|
||||
"\n",
|
||||
" # Output model proto to file.\n",
|
||||
" if output_proto:\n",
|
||||
" output_file = open(output_proto, 'w')\n",
|
||||
" if output_proto_file:\n",
|
||||
" output_file = open(output_proto_file, 'w')\n",
|
||||
" output_file.write(str(model.Proto()))\n",
|
||||
" output_file.close()\n",
|
||||
"\n",
|
||||
@@ -333,7 +333,7 @@
|
||||
"\n",
|
||||
"\"\"\"Main function\"\"\"\n",
|
||||
"if args.solver == 'sat':\n",
|
||||
" solve_cutting_stock_with_arc_flow_and_sat(args.output_proto)\n",
|
||||
" solve_cutting_stock_with_arc_flow_and_sat(args.output_proto_file)\n",
|
||||
"else: # 'mip'\n",
|
||||
" solve_cutting_stock_with_arc_flow_and_mip()\n",
|
||||
"\n"
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
"PARSER.add_argument(\n",
|
||||
" '--instance', default=1, type=int, help='Instance number (1..3).')\n",
|
||||
"PARSER.add_argument(\n",
|
||||
" '--output_proto',\n",
|
||||
" '--output_proto_file',\n",
|
||||
" default=\"\",\n",
|
||||
" help='Output file to write the cp_model'\n",
|
||||
" 'proto to.')\n",
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
"\n",
|
||||
"FLAGS = flags.FLAGS\n",
|
||||
"\n",
|
||||
"flags.DEFINE_string('output_proto', '',\n",
|
||||
"flags.DEFINE_string('output_proto_file', '',\n",
|
||||
" 'Output file to write the cp_model proto to.')\n",
|
||||
"flags.DEFINE_string('params', 'num_search_workers:8,log_search_progress:true',\n",
|
||||
" 'Sat solver parameters.')\n",
|
||||
@@ -2001,9 +2001,9 @@
|
||||
" model.Minimize(\n",
|
||||
" cp_model.LinearExpr.ScalProd(delay_literals, delay_weights))\n",
|
||||
"\n",
|
||||
" if not minimize_drivers and FLAGS.output_proto:\n",
|
||||
" print('Writing proto to %s' % FLAGS.output_proto)\n",
|
||||
" with open(FLAGS.output_proto, 'w') as text_file:\n",
|
||||
" if not minimize_drivers and FLAGS.output_proto_file:\n",
|
||||
" print('Writing proto to %s' % FLAGS.output_proto_file)\n",
|
||||
" with open(FLAGS.output_proto_file, 'w') as text_file:\n",
|
||||
" text_file.write(str(model))\n",
|
||||
"\n",
|
||||
" # Solve model.\n",
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
"FLAGS = flags.FLAGS\n",
|
||||
"\n",
|
||||
"flags.DEFINE_string('input', '', 'Input file to parse and solve.')\n",
|
||||
"flags.DEFINE_string('output_proto', '',\n",
|
||||
"flags.DEFINE_string('output_proto_file', '',\n",
|
||||
" 'Output file to write the cp_model proto to.')\n",
|
||||
"flags.DEFINE_string('params', '', 'Sat solver parameters.')\n",
|
||||
"flags.DEFINE_bool('use_interval_makespan', True,\n",
|
||||
@@ -375,7 +375,7 @@
|
||||
"\n",
|
||||
"rcpsp_parser = pywraprcpsp.RcpspParser()\n",
|
||||
"rcpsp_parser.ParseFile(FLAGS.input)\n",
|
||||
"SolveRcpsp(rcpsp_parser.Problem(), FLAGS.output_proto, FLAGS.params)\n",
|
||||
"SolveRcpsp(rcpsp_parser.Problem(), FLAGS.output_proto_file, FLAGS.params)\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"\n",
|
||||
"FLAGS = flags.FLAGS\n",
|
||||
"\n",
|
||||
"flags.DEFINE_string('output_proto', '',\n",
|
||||
"flags.DEFINE_string('output_proto_file', '',\n",
|
||||
" 'Output file to write the cp_model proto to.')\n",
|
||||
"flags.DEFINE_string('params', 'max_time_in_seconds:10.0',\n",
|
||||
" 'Sat solver parameters.')\n",
|
||||
@@ -252,7 +252,7 @@
|
||||
" return cost_variables, cost_coefficients\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def solve_shift_scheduling(params, output_proto):\n",
|
||||
"def solve_shift_scheduling(params, output_proto_file):\n",
|
||||
" \"\"\"Solves the shift scheduling problem.\"\"\"\n",
|
||||
" # Data\n",
|
||||
" num_employees = 8\n",
|
||||
@@ -437,9 +437,9 @@
|
||||
" sum(obj_int_vars[i] * obj_int_coeffs[i]\n",
|
||||
" for i in range(len(obj_int_vars))))\n",
|
||||
"\n",
|
||||
" if output_proto:\n",
|
||||
" print('Writing proto to %s' % output_proto)\n",
|
||||
" with open(output_proto, 'w') as text_file:\n",
|
||||
" if output_proto_file:\n",
|
||||
" print('Writing proto to %s' % output_proto_file)\n",
|
||||
" with open(output_proto_file, 'w') as text_file:\n",
|
||||
" text_file.write(str(model))\n",
|
||||
"\n",
|
||||
" # Solve the model.\n",
|
||||
@@ -486,7 +486,7 @@
|
||||
" print(' - wall time : %f s' % solver.WallTime())\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"solve_shift_scheduling(FLAGS.params, FLAGS.output_proto)\n",
|
||||
"solve_shift_scheduling(FLAGS.params, FLAGS.output_proto_file)\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
"# Command line arguments.\n",
|
||||
"PARSER = argparse.ArgumentParser()\n",
|
||||
"PARSER.add_argument(\n",
|
||||
" '--output_proto',\n",
|
||||
" '--output_proto_file',\n",
|
||||
" default='',\n",
|
||||
" help='Output file to write the cp_model'\n",
|
||||
" 'proto to.')\n",
|
||||
@@ -121,7 +121,7 @@
|
||||
"\"\"\"Solves a complex single machine jobshop scheduling problem.\"\"\"\n",
|
||||
"\n",
|
||||
"parameters = args.params\n",
|
||||
"output_proto = args.output_proto\n",
|
||||
"output_proto_file = args.output_proto_file\n",
|
||||
"\n",
|
||||
"#----------------------------------------------------------------------------\n",
|
||||
"# Data.\n",
|
||||
@@ -319,9 +319,9 @@
|
||||
"\n",
|
||||
"#----------------------------------------------------------------------------\n",
|
||||
"# Write problem to file.\n",
|
||||
"if output_proto:\n",
|
||||
" print('Writing proto to %s' % output_proto)\n",
|
||||
" with open(output_proto, 'w') as text_file:\n",
|
||||
"if output_proto_file:\n",
|
||||
" print('Writing proto to %s' % output_proto_file)\n",
|
||||
" with open(output_proto_file, 'w') as text_file:\n",
|
||||
" text_file.write(str(model))\n",
|
||||
"\n",
|
||||
"#----------------------------------------------------------------------------\n",
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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.')
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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__':
|
||||
|
||||
@@ -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__':
|
||||
|
||||
@@ -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))
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user