How can I get the mathematical expression for a specific constraint id?
回答済みIn my log, as shown below, I see that the initial incumbent solution violates constraint R212895/R42845. I want to know which constraint is this or the mathematical expression associated with this constraint. How can I retrieve it?
Thanks
Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (linux64) CPU model: AMD EPYC 7763 64-Core Processor, instruction set [SSE2|AVX|AVX2] Thread count: 16 physical cores, 16 logical processors, using up to 16 threads
Optimize a model with 212165 rows, 77908 columns and 590482 nonzeros
Model fingerprint: 0x9bab3eed
Variable types: 55968 continuous, 21940 integer (21578 binary)
Coefficient statistics:
Matrix range [1e-03, 1e+05]
Objective range [6e-02, 6e-02]
Bounds range [1e+00, 3e+00]
RHS range [1e-02, 6e+07]
User MIP start did not produce a new incumbent solution
User MIP start violates constraint R42845 by 0.057142857
MIP start from previous solve did not produce a new incumbent solution
MIP start from previous solve violates constraint R212895 by 4.000000000
Presolve removed 211073 rows and 76468 columns
Presolve time: 2.60s
Presolved: 1092 rows, 1440 columns, 4764 nonzeros
Variable types: 1254 continuous, 186 integer (186 binary)
Found heuristic solution: objective 24.5714014
Root barrier log...
Ordering time: 0.00s
Barrier statistics:
AA' NZ : 5.160e+03
Factor NZ : 2.888e+04 (roughly 1 MB of memory)
Factor Ops : 1.693e+06 (less than 1 second per iteration)
Threads : 1
Objective Residual
Iter Primal Dual Primal Dual Compl Time
0 -1.25259726e+03 -6.23094227e+03 1.05e+02 8.35e-02 1.67e+01 3s
1 -3.53857784e+01 -3.42188876e+03 4.01e+00 8.31e-02 1.93e+00 3s
2 6.10459328e+00 -4.08104077e+02 4.65e-01 2.71e-03 2.00e-01 3s
3 7.69909404e+00 -4.24086445e+01 4.22e-02 1.53e-04 2.22e-02 3s
4 2.48137905e+00 -3.92943961e+00 1.67e-04 4.16e-16 2.72e-03 3s
5 9.18955195e-01 6.09666024e-01 2.12e-06 2.22e-16 1.31e-04 3s
6 8.75793516e-01 8.72806625e-01 2.61e-11 2.22e-16 1.27e-06 3s
7 8.75463888e-01 8.75457958e-01 4.69e-12 2.22e-16 2.51e-09 3s
8 8.75463125e-01 8.75463125e-01 8.15e-12 4.44e-16 2.53e-15 3s
Barrier solved model in 8 iterations and 2.83 seconds (2.16 work units)
Optimal objective 8.75463125e-01
Restart crossover...
Root relaxation: objective 8.754631e-01, 77 iterations, 0.06 seconds (0.02 work units)
Another try with MIP start
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
H 0 0 0.8754631 0.87546 0.00% - 2s
0 0 0.87546 0 1 0.87546 0.87546 0.00% - 2s
Explored 1 nodes (77 simplex iterations) in 2.88 seconds (2.18 work units)
Thread count was 16 (of 16 available processors)
Solution count 2: 0.875463 24.5714
Optimal solution found (tolerance 0.00e+00)
Best objective 8.754631250005e-01, best bound 8.754631250005e-01, gap 0.0000%
0
-
正式なコメント
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
-
You can use the write method to write out your models to a human-readable format
model.write("myLP.lp")You can open the file myLP.lp in any standard text editor and search for the constraint name.
Or: -
You write a script in a similar way as discussed How do I access the left-hand side of a constraint?, for example
import gurobipy as gp
m=gp.read("data/glass4.mps")
m.read("sol.sol")
m.update()
con = m.getConstrByName("c15")
lexpr = m.getRow(con)
lhs = 0
for i in range(lexpr.size()):
coeff = lexpr.getCoeff(i)
var = lexpr.getVar(i)
lhs += coeff * var.Start
print(f"{m.getRow(con)} {con.Sense} {con.RHS}")
print(f"{lhs} {con.Sense} {con.RHS}")
0 -
投稿コメントは受け付けていません。
コメント
2件のコメント