03/12, 2020
library(tidyverse) # Manejo de datos y gráficos library(raster) # Manejo de datos espaciales (rasters) library(sf) # Manejo de datos espaciales (polígonos) library(prioritizr) # priorización library(gurobi) # Solver
p_Naidoo <- problem(Costo$Naidoo, Consensos) %>% add_min_set_objective() %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_gurobi_solver() p_Plano <- problem(Costo$Plano, Consensos) %>% add_min_set_objective() %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_gurobi_solver()
Sols_Naidoo <- solve(p_Naidoo) Sols_Plano <- solve(p_Plano)
## Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64) ## Optimize a model with 29 rows, 164684 columns and 998013 nonzeros ## Model fingerprint: 0x66d9284f ## Variable types: 0 continuous, 164684 integer (164684 binary) ## Coefficient statistics: ## Matrix range [1e+00, 1e+00] ## Objective range [1e+00, 6e+02] ## Bounds range [1e+00, 1e+00] ## RHS range [2e+00, 2e+04] ## Found heuristic solution: objective 1842628.0628 ## Presolve removed 1 rows and 82634 columns ## Presolve time: 1.56s ## Presolved: 28 rows, 82050 columns, 533263 nonzeros ## Variable types: 0 continuous, 82050 integer (58039 binary) ## Presolved: 28 rows, 82050 columns, 533263 nonzeros ## ## ## Starting sifting (using dual simplex for sub-problems)... ## ## Iter Pivots Primal Obj Dual Obj Time ## 0 0 infinity 0.0000000e+00 2s ## 1 25 1.0421256e+10 7.0368910e+03 2s ## 2 76 1.0419506e+10 7.0529438e+03 2s ## 3 126 1.0417756e+10 7.0767945e+03 2s ## 4 176 1.0405506e+10 7.1033508e+03 2s ## 5 226 1.0403756e+10 7.2905104e+03 2s ## 6 276 1.0398506e+10 7.3541239e+03 2s ## 7 326 1.0395006e+10 7.4809435e+03 2s ## 8 378 1.0391381e+10 7.5128850e+03 2s ## 9 428 1.0387881e+10 7.5763816e+03 2s ## 10 478 1.0337506e+10 7.5766114e+03 2s ## 11 529 1.0318006e+10 7.6102515e+03 2s ## 12 587 1.0180137e+10 7.6444278e+03 2s ## 13 647 1.0048888e+10 7.7126750e+03 2s ## 14 706 9.7806421e+09 7.9151632e+03 2s ## 15 765 9.4956468e+09 8.2228686e+03 2s ## 16 824 9.2412781e+09 8.5536360e+03 2s ## 17 885 9.0479091e+09 8.9271265e+03 2s ## 18 946 8.6301784e+09 9.1019769e+03 2s ## 19 1007 8.4165646e+09 9.2770684e+03 2s ## 20 1068 8.1565805e+09 9.5633353e+03 2s ## 21 1127 7.9457189e+09 9.8450389e+03 2s ## 22 1185 7.8104715e+09 1.0049370e+04 2s ## 23 1242 7.6003545e+09 1.0223423e+04 2s ## 24 1299 7.4579820e+09 1.0515004e+04 2s ## 25 1358 7.2864855e+09 1.0933681e+04 2s ## 26 1416 7.1173652e+09 1.1313019e+04 2s ## 27 1476 6.9798711e+09 1.1818986e+04 2s ## 28 1530 6.8046283e+09 1.2315945e+04 2s ## 29 1584 6.7002559e+09 1.2649854e+04 2s ## 30 1637 6.5798845e+09 1.3046848e+04 2s ## 31 1695 6.4505139e+09 1.3578797e+04 2s ## 32 1749 6.3078948e+09 1.4150049e+04 2s ## 33 1806 6.1835256e+09 1.4719136e+04 2s ## 34 1858 6.0516587e+09 1.5282682e+04 2s ## 35 1910 5.9156692e+09 1.5715583e+04 2s ## 36 1961 5.7492998e+09 1.6193844e+04 2s ## 37 2012 5.6204297e+09 1.6318531e+04 2s ## 38 2062 5.5484331e+09 1.6562351e+04 2s ## 39 2113 5.4234422e+09 1.6851391e+04 2s ## 40 2160 5.3016953e+09 1.7246914e+04 2s ## 41 2212 5.2129485e+09 1.7759824e+04 2s ## 42 2261 5.1202050e+09 1.8222562e+04 2s ## 43 2313 4.9974575e+09 1.8814975e+04 2s ## 44 2366 4.8715847e+09 1.9390677e+04 2s ## 45 2416 4.7719620e+09 1.9663823e+04 2s ## 46 2464 4.6944642e+09 1.9817653e+04 2s ## 47 2512 4.6259661e+09 1.9889196e+04 3s ## 48 2558 4.4318501e+09 1.9927450e+04 3s ## 49 2606 4.2971121e+09 1.9996185e+04 3s ## ## Sifting complete ## ## ## Root relaxation: objective 1.266106e+05, 2712 iterations, 0.95 seconds ## ## Nodes | Current Node | Objective Bounds | Work ## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time ## ## * 0 0 0 126610.59120 126610.591 0.00% - 2s ## ## Explored 0 nodes (2712 simplex iterations) in 3.01 seconds ## Thread count was 1 (of 8 available processors) ## ## Solution count 2: 126611 1.84263e+06 ## ## Optimal solution found (tolerance 1.00e-01) ## Best objective 1.266105911991e+05, best bound 1.266105911991e+05, gap 0.0000% ## Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64) ## Optimize a model with 29 rows, 164684 columns and 998013 nonzeros ## Model fingerprint: 0x13f4c8b4 ## Variable types: 0 continuous, 164684 integer (164684 binary) ## Coefficient statistics: ## Matrix range [1e+00, 1e+00] ## Objective range [2e+00, 2e+00] ## Bounds range [1e+00, 1e+00] ## RHS range [2e+00, 2e+04] ## Found heuristic solution: objective 32768.000000 ## Presolve removed 1 rows and 163068 columns ## Presolve time: 0.41s ## Presolved: 28 rows, 1616 columns, 16271 nonzeros ## Variable types: 0 continuous, 1616 integer (321 binary) ## Presolved: 28 rows, 1616 columns, 16271 nonzeros ## ## ## Root relaxation: cutoff, 0 iterations, 0.01 seconds ## ## Explored 0 nodes (0 simplex iterations) in 0.48 seconds ## Thread count was 1 (of 8 available processors) ## ## Solution count 1: 32768 ## ## Optimal solution found (tolerance 1.00e-01) ## Best objective 3.276800000000e+04, best bound 3.276800000000e+04, gap 0.0000%
p_Naidoo_PA <- problem(Costo$Naidoo, Consensos) %>% add_min_set_objective() %>% add_locked_in_constraints(PA) %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_gurobi_solver() Sols_Naidoo_PA <- solve(p_Naidoo_PA)
## Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64) ## Optimize a model with 29 rows, 164684 columns and 998013 nonzeros ## Model fingerprint: 0xeb65947a ## Variable types: 0 continuous, 164684 integer (164684 binary) ## Coefficient statistics: ## Matrix range [1e+00, 1e+00] ## Objective range [1e+00, 6e+02] ## Bounds range [1e+00, 1e+00] ## RHS range [2e+00, 2e+04] ## Found heuristic solution: objective 1673501.2060 ## Presolve removed 2 rows and 84665 columns ## Presolve time: 1.56s ## Presolved: 27 rows, 80019 columns, 519341 nonzeros ## Variable types: 0 continuous, 80019 integer (56599 binary) ## Presolved: 27 rows, 80019 columns, 519341 nonzeros ## ## ## Starting sifting (using dual simplex for sub-problems)... ## ## Iter Pivots Primal Obj Dual Obj Time ## 0 0 infinity 1.6813385e+05 2s ## 1 25 7.3380493e+09 1.7336309e+05 2s ## 2 75 7.3345493e+09 1.7339273e+05 2s ## 3 125 7.3240493e+09 1.7341245e+05 2s ## 4 175 7.3222993e+09 1.7355141e+05 2s ## 5 225 7.3170493e+09 1.7359864e+05 2s ## 6 275 7.3135493e+09 1.7369278e+05 2s ## 7 328 7.3099243e+09 1.7371649e+05 2s ## 8 378 7.3064243e+09 1.7376361e+05 2s ## 9 428 7.2560493e+09 1.7376378e+05 2s ## 10 479 7.2365493e+09 1.7378868e+05 2s ## 11 535 7.2271745e+09 1.7379585e+05 2s ## 12 592 7.0900547e+09 1.7382809e+05 2s ## 13 652 6.9658061e+09 1.7391331e+05 2s ## 14 711 6.7496841e+09 1.7411986e+05 2s ## 15 767 6.5821919e+09 1.7446327e+05 2s ## 16 827 6.4401945e+09 1.7478583e+05 2s ## 17 887 6.2000763e+09 1.7503942e+05 2s ## 18 943 6.0785790e+09 1.7513185e+05 2s ## 19 1001 5.9433337e+09 1.7531384e+05 2s ## 20 1058 5.7943366e+09 1.7568524e+05 2s ## 21 1112 5.6547141e+09 1.7596344e+05 2s ## 22 1167 5.4535950e+09 1.7620600e+05 2s ## 23 1224 5.3118492e+09 1.7660778e+05 2s ## 24 1280 5.1724790e+09 1.7691655e+05 2s ## 25 1339 5.0171105e+09 1.7735189e+05 2s ## 26 1395 4.8696171e+09 1.7772638e+05 2s ## 27 1449 4.7576231e+09 1.7821082e+05 2s ## 28 1500 4.6415036e+09 1.7858611e+05 2s ## 29 1550 4.4678834e+09 1.7894295e+05 2s ## 30 1606 4.3673905e+09 1.7935366e+05 2s ## 31 1655 4.2705176e+09 1.7977019e+05 2s ## 32 1703 4.1763991e+09 1.8035538e+05 2s ## 33 1753 4.0706644e+09 1.8084960e+05 2s ## 34 1804 3.9692905e+09 1.8104692e+05 2s ## 35 1853 3.8909170e+09 1.8120280e+05 2s ## 36 1900 3.7894196e+09 1.8130911e+05 2s ## 37 1949 3.6804223e+09 1.8148829e+05 2s ## 38 1991 3.5904251e+09 1.8168890e+05 2s ## 39 2032 3.4991784e+09 1.8190291e+05 2s ## 40 2077 3.3956824e+09 1.8230828e+05 2s ## 41 2117 3.3070619e+09 1.8273237e+05 2s ## 42 2160 3.1854414e+09 1.8311073e+05 2s ## 43 2203 3.0700668e+09 1.8332580e+05 2s ## 44 2247 3.0034423e+09 1.8336234e+05 2s ## 45 2291 2.9093195e+09 1.8336623e+05 2s ## 46 2332 2.8010731e+09 1.8337352e+05 2s ## 47 2375 2.7315742e+09 1.8339114e+05 2s ## 48 2414 2.6800750e+09 1.8342566e+05 3s ## 49 2454 2.6068264e+09 1.8348319e+05 3s ## ## Sifting complete ## ## ## Root relaxation: objective 2.735645e+05, 2539 iterations, 0.92 seconds ## ## Nodes | Current Node | Objective Bounds | Work ## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time ## ## * 0 0 0 273564.47817 273564.478 0.00% - 2s ## ## Explored 0 nodes (2539 simplex iterations) in 2.96 seconds ## Thread count was 1 (of 8 available processors) ## ## Solution count 2: 273564 1.6735e+06 ## ## Optimal solution found (tolerance 1.00e-01) ## Best objective 2.735644781668e+05, best bound 2.735644781668e+05, gap 0.0000%
p_Naidoo_PA_FP <- problem(Costo$Naidoo, Consensos) %>% add_min_set_objective() %>% add_locked_in_constraints(PA) %>% add_locked_out_constraints(Impacto) %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_gurobi_solver() Sols_Naidoo_PA_FP <- solve(p_Naidoo_PA_FP)
## Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64) ## Optimize a model with 29 rows, 164684 columns and 998013 nonzeros ## Model fingerprint: 0x81112498 ## Variable types: 0 continuous, 164684 integer (164684 binary) ## Coefficient statistics: ## Matrix range [1e+00, 1e+00] ## Objective range [1e+00, 6e+02] ## Bounds range [1e+00, 1e+00] ## RHS range [2e+00, 2e+04] ## Found heuristic solution: objective 1429747.0916 ## Presolve removed 2 rows and 96229 columns ## Presolve time: 1.78s ## Presolved: 27 rows, 68455 columns, 417964 nonzeros ## Variable types: 0 continuous, 68455 integer (48708 binary) ## Presolved: 27 rows, 68455 columns, 417964 nonzeros ## ## ## Starting sifting (using dual simplex for sub-problems)... ## ## Iter Pivots Primal Obj Dual Obj Time ## 0 0 infinity 1.6108813e+05 2s ## 1 26 7.4291671e+09 1.6635644e+05 2s ## 2 72 7.4256671e+09 1.6638630e+05 2s ## 3 121 7.4151671e+09 1.6640616e+05 2s ## 4 170 7.4134171e+09 1.6654617e+05 2s ## 5 219 7.4081671e+09 1.6659375e+05 2s ## 6 265 7.4046671e+09 1.6668860e+05 2s ## 7 314 7.4010421e+09 1.6671249e+05 2s ## 8 360 7.3975421e+09 1.6675996e+05 2s ## 9 406 7.3471671e+09 1.6676014e+05 2s ## 10 454 7.3276671e+09 1.6678523e+05 2s ## 11 504 7.3184172e+09 1.6679244e+05 2s ## 12 563 7.2420431e+09 1.6682493e+05 2s ## 13 622 7.1534217e+09 1.6691080e+05 2s ## 14 682 7.0147981e+09 1.6710455e+05 2s ## 15 741 6.8476751e+09 1.6741152e+05 2s ## 16 796 6.6976781e+09 1.6772053e+05 2s ## 17 853 6.4779304e+09 1.6793052e+05 2s ## 18 907 6.3450578e+09 1.6801708e+05 2s ## 19 966 6.2381859e+09 1.6817265e+05 2s ## 20 1024 6.1005642e+09 1.6844486e+05 2s ## 21 1082 5.9585672e+09 1.6867828e+05 2s ## 22 1143 5.7943218e+09 1.6892571e+05 2s ## 23 1199 5.6753258e+09 1.6918088e+05 2s ## 24 1252 5.4998326e+09 1.6957827e+05 2s ## 25 1306 5.3502140e+09 1.6989325e+05 2s ## 26 1359 5.2552204e+09 1.7030000e+05 2s ## 27 1414 5.1222224e+09 1.7060371e+05 2s ## 28 1468 5.0179750e+09 1.7095184e+05 2s ## 29 1517 4.8778540e+09 1.7136357e+05 2s ## 30 1569 4.7584822e+09 1.7170338e+05 2s ## 31 1618 4.6337378e+09 1.7200943e+05 2s ## 32 1672 4.5303681e+09 1.7236324e+05 2s ## 33 1724 4.3963727e+09 1.7269612e+05 2s ## 34 1776 4.3005015e+09 1.7333449e+05 2s ## 35 1823 4.2020063e+09 1.7373466e+05 2s ## 36 1872 4.1228823e+09 1.7393732e+05 2s ## 37 1919 4.0396343e+09 1.7403646e+05 2s ## 38 1966 3.9527613e+09 1.7413241e+05 2s ## 39 2014 3.8440154e+09 1.7423363e+05 2s ## 40 2061 3.7570190e+09 1.7442178e+05 2s ## 41 2108 3.6761477e+09 1.7470395e+05 2s ## 42 2154 3.5835270e+09 1.7519778e+05 2s ## 43 2204 3.4685333e+09 1.7568684e+05 3s ## 44 2248 3.3805363e+09 1.7616915e+05 3s ## 45 2294 3.2477935e+09 1.7639045e+05 3s ## 46 2337 3.1569251e+09 1.7648791e+05 3s ## 47 2385 3.0911785e+09 1.7651193e+05 3s ## 48 2433 2.9649422e+09 1.7652151e+05 3s ## 49 2475 2.8843175e+09 1.7654937e+05 3s ## ## Sifting complete ## ## ## Root relaxation: objective 2.771919e+05, 2596 iterations, 0.79 seconds ## ## Nodes | Current Node | Objective Bounds | Work ## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time ## ## * 0 0 0 277191.93559 277191.936 0.00% - 2s ## ## Explored 0 nodes (2596 simplex iterations) in 2.96 seconds ## Thread count was 1 (of 8 available processors) ## ## Solution count 2: 277192 1.42975e+06 ## ## Optimal solution found (tolerance 1.00e-01) ## Best objective 2.771919355937e+05, best bound 2.771919355937e+05, gap 0.0000%
p_Naidoo_PA_FP_Test <- problem(Costo$Naidoo, Consensos) %>% add_min_set_objective() %>% add_locked_in_constraints(PA) %>% add_locked_out_constraints(Impacto) %>% add_relative_targets(0.1) %>% add_boundary_penalties(penalty = 100) %>% add_binary_decisions() %>% add_gurobi_solver() Sols_Naidoo_PA_FP_Test <- solve(p_Naidoo_PA_FP_Test)
## Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64) ## Optimize a model with 654817 rows, 492078 columns and 2307589 nonzeros ## Model fingerprint: 0x6f29f689 ## Variable types: 0 continuous, 492078 integer (492078 binary) ## Coefficient statistics: ## Matrix range [1e+00, 1e+00] ## Objective range [2e+00, 6e+02] ## Bounds range [1e+00, 1e+00] ## RHS range [2e+00, 2e+04] ## Found heuristic solution: objective 1438966.2582 ## Presolve removed 131474 rows and 95553 columns (presolve time = 6s) ... ## Presolve removed 131478 rows and 95553 columns ## Presolve time: 6.73s ## Presolved: 523339 rows, 396525 columns, 1802973 nonzeros ## Found heuristic solution: objective 542816.83698 ## Variable types: 0 continuous, 396525 integer (396524 binary) ## Presolved: 523339 rows, 396525 columns, 1802973 nonzeros ## ## ## Root simplex log... ## ## Iteration Objective Primal Inf. Dual Inf. Time ## 0 1.6293459e+05 7.445000e+04 0.000000e+00 9s ## 7773 2.7531985e+05 1.208497e+05 0.000000e+00 10s ## 19474 2.8309582e+05 6.198350e+04 0.000000e+00 15s ## 23814 2.8332110e+05 1.769467e+04 0.000000e+00 21s ## 26214 2.8344743e+05 1.029323e+04 0.000000e+00 26s ## 29184 2.8364571e+05 1.207571e+04 0.000000e+00 31s ## 30634 2.8372633e+05 5.029832e+03 0.000000e+00 36s ## 31764 2.8376391e+05 1.299016e+04 0.000000e+00 41s ## 33014 2.8382320e+05 8.540229e+03 0.000000e+00 45s ## 34804 2.8388234e+05 1.610007e+03 0.000000e+00 51s ## 36444 2.8391964e+05 9.883861e+02 0.000000e+00 56s ## 37774 2.8393178e+05 5.300776e+01 0.000000e+00 61s ## 38148 2.8393263e+05 0.000000e+00 0.000000e+00 63s ## 38148 2.8393263e+05 0.000000e+00 0.000000e+00 63s ## ## Root relaxation: objective 2.839326e+05, 38148 iterations, 55.22 seconds ## ## Nodes | Current Node | Objective Bounds | Work ## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time ## ## 0 0 283932.626 0 733 542816.837 283932.626 47.7% - 64s ## H 0 0 284397.56946 283932.626 0.16% - 65s ## ## Explored 1 nodes (38149 simplex iterations) in 65.36 seconds ## Thread count was 1 (of 8 available processors) ## ## Solution count 3: 284398 542817 1.43897e+06 ## ## Optimal solution found (tolerance 1.00e-01) ## Best objective 2.843975694610e+05, best bound 2.839326261741e+05, gap 0.1635%
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
p_Naidoo_PA_FP_Test <- problem(Costo$Naidoo, Formaciones) %>% add_min_set_objective() %>% add_locked_in_constraints(PA) %>% add_locked_out_constraints(Impacto) %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_gurobi_solver() Sols_Formacion <- solve(p_Naidoo_PA_FP_Test)
## Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64) ## Optimize a model with 9 rows, 164684 columns and 162512 nonzeros ## Model fingerprint: 0x4ca49965 ## Variable types: 0 continuous, 164684 integer (164684 binary) ## Coefficient statistics: ## Matrix range [1e+00, 1e+00] ## Objective range [1e+00, 6e+02] ## Bounds range [1e+00, 1e+00] ## RHS range [2e+02, 4e+03] ## Found heuristic solution: objective 1233871.8948 ## Presolve removed 8 rows and 152519 columns ## Presolve time: 0.44s ## Presolved: 1 rows, 12165 columns, 12165 nonzeros ## Found heuristic solution: objective 671726.97576 ## Variable types: 0 continuous, 12165 integer (8186 binary) ## Presolved: 1 rows, 12165 columns, 12165 nonzeros ## ## ## Root relaxation: objective 3.126127e+05, 1 iterations, 0.01 seconds ## ## Nodes | Current Node | Objective Bounds | Work ## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time ## ## * 0 0 0 312612.68274 312612.683 0.00% - 0s ## ## Explored 0 nodes (1 simplex iterations) in 0.54 seconds ## Thread count was 1 (of 8 available processors) ## ## Solution count 3: 312613 671727 1.23387e+06 ## ## Optimal solution found (tolerance 1.00e-01) ## Best objective 3.126126827382e+05, best bound 3.126126827382e+05, gap 0.0000%