Pyomo: AttributeError: у объекта 'dict' нет атрибута '__default_objective__' - PullRequest
0 голосов
/ 27 июня 2018

https://github.com/amianAA/ALNS содержит файлы, написанные на python и pyomo с алгоритмом ALNS для оптимизации моделей железнодорожных сетей MINLP (применяется к сети Мадрида). Все работает нормально, но я получил ошибку в этой функции:

def solveFO(instance):
    opt = SolverFactory(str(solver))
    results = opt.solve(instance, tee=True)
    instance.load(results)
    return float(results.Solution.Objective.__default_objective__['value'])

Вывод и ошибка :

Time creating the model: 11 minutos 20 segundos
Academic license - for non-commercial use only
Optimize a model with 62941 rows, 175536 columns and 564324 nonzeros
Variable types: 953 continuous, 174583 integer (3733 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+08]
  Objective range  [1e+00, 1e+00]
  Bounds range     [1e+00, 1e+00]
  RHS range        [1e+00, 5e+02]
Presolve removed 46175 rows and 104643 columns
Presolve time: 2.62s
Presolved: 16766 rows, 70893 columns, 158005 nonzeros
Variable types: 0 continuous, 70893 integer (0 binary)

Deterministic concurrent LP optimizer: primal and dual simplex
Showing first log only...

Presolve removed 636 rows and 23 columns
Presolved: 16130 rows, 70870 columns, 154117 nonzeros

Presolve removed 11677 rows and 57179 columns

Root simplex log...

Iteration    Objective       Primal Inf.    Dual Inf.      Time
   0    3.8005345e+11   4.118750e+02   2.291190e+08      5s
  26    5.0222580e+11   0.000000e+00   6.321933e+08      5s
Concurrent spin time: 0.00s

Solved with dual simplex

Root relaxation: objective 1.598284e+11, 7355 iterations, 2.48 seconds

  Nodes    |    Current Node    |     Objective Bounds      |     Work
  Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

*    0     0               0    1.598284e+11 1.5983e+11  0.00%     -    6s

Explored 0 nodes (7355 simplex iterations) in 6.09 seconds
Thread count was 2 (of 2 available processors)

Solution count 1: 1.59828e+11 

Optimal solution found (tolerance 1.00e-04)
Best objective 1.598283725288e+11, best bound 1.598283725288e+11, gap 0.0000%
Freed default Gurobi environment
WARNING: DEPRECATION WARNING: the Model.load() method is deprecated for
  loading solutions stored in SolverResults objects.  By default, results
  from solvers are immediately loaded into the original model instance.
Traceback (most recent call last):
File "ALNS.py", line 117, in <module>
  solref = solveFO(instance)
File "ALNS.py", line 35, in solveFO
  return float(results.Solution.Objective.__default_objective__['value'])
AttributeError: 'dict' object has no attribute '__default_objective__'

Заранее благодарим за любые руки помощи!

1 Ответ

0 голосов
/ 27 июня 2018

Поскольку вы объявили model.obj = Objective(), вы можете использовать value(model.obj) для получения значения цели,

...