Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

python - PuLP CBC warm start immediately accepts initial solution

I'm currently working on a scheduling problem using pulp with the default CBC solver. The problem is quite big so i wanted to use warm start and set the variables for a random feasible initial solution. But the solver stops after 0 iterations with the initial solution as optimal solution. I would expect the solver to start from here and search for a better solution

So i ran the code example from the Pulp Warm Start Documentation and the same thing happens. I didn't touch the code example. Is something wrong with my PuLp installation or did I get the idea of a warm start wrong?

I run this code on a PyCharm Python3.8 venv

https://coin-or.github.io/pulp/guides/how_to_mip_start.html

"""
A set partitioning model of a wedding seating problem
Adaptation where an initial solution is given to solvers: CPLEX_CMD, GUROBI_CMD, PULP_CBC_CMD

Authors: Stuart Mitchell 2009, Franco Peschiera 2019
"""

import pulp

max_tables = 5
max_table_size = 4
guests = 'A B C D E F G I J K L M N O P Q R'.split()


def happiness(table):
    """
    Find the happiness of the table
    - by calculating the maximum distance between the letters
    """
    return abs(ord(table[0]) - ord(table[-1]))


# create list of all possible tables
possible_tables = [tuple(c) for c in pulp.allcombinations(guests,
                                                          max_table_size)]

# create a binary variable to state that a table setting is used
x = pulp.LpVariable.dicts('table', possible_tables,
                          lowBound=0,
                          upBound=1,
                          cat=pulp.LpInteger)

seating_model = pulp.LpProblem("Wedding Seating Model", pulp.LpMinimize)

seating_model += pulp.lpSum([happiness(table) * x[table] for table in possible_tables])

# specify the maximum number of tables
seating_model += pulp.lpSum([x[table] for table in possible_tables]) <= max_tables, 
                 "Maximum_number_of_tables"

# A guest must seated at one and only one table
for guest in guests:
    seating_model += pulp.lpSum([x[table] for table in possible_tables
                          if guest in table]) == 1, "Must_seat_%s" % guest

# I've taken the optimal solution from a previous solving. x is the variable dictionary.
solution = {
    ('M', 'N'): 1.0,
    ('E', 'F', 'G'): 1.0,
    ('A', 'B', 'C', 'D'): 1.0,
    ('I', 'J', 'K', 'L'): 1.0,
    ('O', 'P', 'Q', 'R'): 1.0
}
for k, v in solution.items():
    x[k].setInitialValue(v)

solver = pulp.PULP_CBC_CMD(msg=True, warmStart=True)
#solver = pulp.CPLEX_CMD(msg=True, warmStart=True)
#solver = pulp.GUROBI_CMD(msg=True, warmStart=True)
# solver = pulp.CPLEX_PY(msg=True, warmStart=True)
# solver = pulp.GUROBI(msg=True, warmStart=True)
seating_model.solve(solver)


print("The choosen tables are out of a total of %s:" % len(possible_tables))
for table in possible_tables:
    if x[table].value() == 1.0:
        print(table)

result output:

Welcome to the CBC MILP Solver 
Version: 2.9.0 
Build Date: Feb 12 2015 

command line - /Users/nicoelbert/Documents/GitHub/WueExam/venv/lib/python3.8/site-packages/pulp/apis/../solverdir/cbc/osx/64/cbc /var/folders/mv/pmsgdhgx6tqdpnq2sy_5k75h0000gn/T/d157dc1b36df4498a14efa89fb14865a-pulp.mps mips /var/folders/mv/pmsgdhgx6tqdpnq2sy_5k75h0000gn/T/d157dc1b36df4498a14efa89fb14865a-pulp.mst branch printingOptions all solution /var/folders/mv/pmsgdhgx6tqdpnq2sy_5k75h0000gn/T/d157dc1b36df4498a14efa89fb14865a-pulp.sol (default strategy 1)
At line 2 NAME          MODEL
At line 3 ROWS
At line 23 COLUMNS
At line 24708 RHS
At line 24727 BOUNDS
At line 27941 ENDATA
Problem MODEL has 18 rows, 3213 columns and 15062 elements
Coin0008I MODEL read with 0 errors
will open mipstart file /var/folders/mv/pmsgdhgx6tqdpnq2sy_5k75h0000gn/T/d157dc1b36df4498a14efa89fb14865a-pulp.mst.
mipstart values read for 3213 variables.
Continuous objective value is 12 - 0.01 seconds
Cgl0004I processed model has 18 rows, 3213 columns (3213 integer (3213 of which binary)) and 15062 elements
Cutoff increment increased from 1e-05 to 0.9999
Cbc0045I mipstart provided solution with cost 12
Cbc0006I The LP relaxation is infeasible or too expensive
Cuts at root node changed objective from 1.79769e+308 to -1.79769e+308
Probing was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Cgl0013I Postprocessed model is infeasible - possible tolerance issue - try without preprocessing
17 relaxed row infeasibilities - summing to 17
17 relaxed row infeasibilities - summing to 17
17 relaxed row infeasibilities - summing to 17

Result - Optimal solution found

Objective value:                12.00000000
Enumerated nodes:               0
Total iterations:               0
Time (CPU seconds):             0.06
Time (Wallclock seconds):       0.07

Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.07   (Wallclock seconds):       0.09

The choosen tables are out of a total of 3213:

Process finished with exit code 0
question from:https://stackoverflow.com/questions/65876774/pulp-cbc-warm-start-immediately-accepts-initial-solution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...