Closed attoman closed 1 year ago
Hi,
You can check out how to set initial solutions for the mixed integer optimizer at https://docs.mosek.com/latest/pythonfusion/tutorial-mio-shared.html#specifying-an-initial-solution
According to that, since you are specifying all the variables (the only variable is x), Mosek should check if it is a feasible solution automatically. You can check if this is done by checking the information item "mioInitialFeasibleSolution":
M.getSolverIntInfo('mioInitialFeasibleSolution')
If this is 1, then initial feasible solution was used. If 0, then there was no initial solution supplied, or it was not feasible.
Thanks for your comments.
While I'm trying an example for the TSP problem, I'm trying a hot-start by entering pre-prepared initial variables. In the case of the TSP problem, it seems that mixed integer optimizer is used. At this time, if the initial input for hot-start is entered as follows, it seems that the initial value is not set properly.
Here is my code.
''' def tsp(n, A, C, remove_selfloops, remove_2_hop_loops, init_value = None): with Model() as M: M.setLogHandler(sys.stdout) M.setSolverParam("presolveUse", "off") x = M.variable("x", [n,n], Domain.binary()) if init_value is None: pass else: x.setLevel(init_value) M.constraint(Expr.sum(x,0), Domain.equalsTo(1.0)) M.constraint(Expr.sum(x,1), Domain.equalsTo(1.0)) M.constraint(x, Domain.lessThan( A ))
X_warm = torch.zeros((n,n)) for i in range(tour_indices.shape[1]): X_warm[i][tour_indices[0][i]] = 1 for j in range(len(indx[0])): X_warm[indx[0][j]][indx[1][j]] = 1 for k in range(n): X_warm[k][k] = 0 X_warm = X_warm.to("cpu") X_warm_np = X_warm.numpy(force=True) X_warm_np_flat = X_warm_np.flatten() X_init_constraint_np = np.ones((n,n)) X_init_constraint_sparse = Matrix.sparse(X_init_constraint_np) X_warm_np = X_warm_np.astype(np.float64) X_warm_sparse = Matrix.sparse(X_warm_np) costs = Matrix.sparse(C_np) x_sol, c, length_sol = tsp(n, X_init_constraint_sparse, costs , True, True, init_value = X_warm_np_flat.tolist())
'''
tour_indices is tour node order.
Any way to solve this problem? Doesn't Mosek provide initial value setting for hot-start in mixed integer optimizer? Or if there is another way to solve this, please guide me.