Li Mike
unread,May 6, 2026, 9:56:17 PM (6 days ago) May 6Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to or-tools-discuss
I tested the following model: if I remove the statement model.add_hint(x[0][1], 30.0), the model solves normally.
However, when I add this statement, the solver returns no output. What is the reason for this?
I tested in ortools 9.14, 9.15 and newest main branch.
from ortools.linear_solver.python import model_builder
def solve_transportation_problem():
costs = [
[8, 6, 10, 9],
[9, 12, 13, 7],
[14, 9, 16, 5]
]
supply = [90, 100, 150]
demand = [20, 30, 80, 40]
num_suppliers = len(supply)
num_customers = len(demand)
model = model_builder.Model()
x = []
for i in range(num_suppliers):
row = []
for j in range(num_customers):
var = model.new_num_var(0.0, float(max(supply)), f'x_{i}_{j}')
row.append(var)
x.append(row)
for i in range(num_suppliers):
model.add(sum(x[i][j] for j in range(num_customers)) <= supply[i])
for j in range(num_customers):
model.add(sum(x[i][j] for i in range(num_suppliers)) >= demand[j])
objective_terms = []
for i in range(num_suppliers):
for j in range(num_customers):
objective_terms.append(x[i][j] * costs[i][j])
model.minimize(sum(objective_terms))
############
# hint
############
model.add_hint(x[0][1], 30.0)
solver = model_builder.Solver('highs')
solver.enable_output(True)
status = solver.solve(model)
print(f'Total Cost = {solver.objective_value}')
if __name__ == '__main__':
solve_transportation_problem()