forked from NVIDIA/cuopt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve.cu
More file actions
2316 lines (2111 loc) · 118 KB
/
Copy pathsolve.cu
File metadata and controls
2316 lines (2111 loc) · 118 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* clang-format off */
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/* clang-format on */
#include <cuopt/error.hpp>
#include <cuopt/linear_programming/solve_remote.hpp>
#include <pdlp/cusparse_view.hpp>
#include <pdlp/optimal_batch_size_handler/optimal_batch_size_handler.hpp>
#include <pdlp/pdlp.cuh>
#include <pdlp/pdlp_constants.hpp>
#include <pdlp/restart_strategy/pdlp_restart_strategy.cuh>
#include <pdlp/step_size_strategy/adaptive_step_size_strategy.hpp>
#include <pdlp/translate.hpp>
#include <pdlp/utilities/ping_pong_graph.cuh>
#include <pdlp/utilities/problem_checking.cuh>
#include <pdlp/utils.cuh>
#include <utilities/logger.hpp>
#include <mip_heuristics/mip_constants.hpp>
#include <mip_heuristics/presolve/third_party_presolve.hpp>
#include <mip_heuristics/presolve/trivial_presolve.cuh>
#include <mip_heuristics/solver.cuh>
#include <mip_heuristics/utilities/sort_csr.cuh>
#include <cuopt/linear_programming/backend_selection.hpp>
#include <cuopt/linear_programming/cpu_optimization_problem.hpp>
#include <cuopt/linear_programming/cpu_optimization_problem_solution.hpp>
#include <cuopt/linear_programming/optimization_problem.hpp>
#include <cuopt/linear_programming/optimization_problem_solution.hpp>
#include <cuopt/linear_programming/optimization_problem_utils.hpp>
#include <cuopt/linear_programming/pdlp/pdlp_hyper_params.cuh>
#include <cuopt/linear_programming/pdlp/solver_settings.hpp>
#include <cuopt/linear_programming/solve.hpp>
#include <cuopt/linear_programming/io/mps_data_model.hpp>
#include <utilities/copy_helpers.hpp>
#include <utilities/omp_helpers.hpp>
#include <utilities/version_info.hpp>
#include <barrier/sparse_cholesky.cuh>
#include <dual_simplex/crossover.hpp>
#include <dual_simplex/solve.hpp>
#include <dual_simplex/tic_toc.hpp>
#include <pdlp/utilities/problem_checking.cuh>
#include <raft/sparse/detail/cusparse_wrappers.h>
#include <raft/core/cusparse_macros.hpp>
#include <raft/core/device_setter.hpp>
#include <raft/core/handle.hpp>
#include <raft/core/nvtx.hpp>
#include <rmm/cuda_stream.hpp>
#include <thrust/iterator/counting_iterator.h>
#include <omp.h>
#include <algorithm>
#include <cmath>
#include <exception>
#include <set>
#include <tuple>
#define CUOPT_LOG_CONDITIONAL_INFO(condition, ...) \
if ((condition)) { CUOPT_LOG_INFO(__VA_ARGS__); }
namespace cuopt::linear_programming {
template <typename From, typename To>
extern rmm::device_uvector<To> gpu_cast(const rmm::device_uvector<From>& src,
rmm::cuda_stream_view stream);
// This serves as both a warm up but also a mandatory initial call to setup cuSparse and cuBLAS
static void init_handler(const raft::handle_t* handle_ptr)
{
// Init cuBlas / cuSparse context here to avoid having it during solving time
RAFT_CUBLAS_TRY(raft::linalg::detail::cublassetpointermode(
handle_ptr->get_cublas_handle(), CUBLAS_POINTER_MODE_DEVICE, handle_ptr->get_stream()));
RAFT_CUSPARSE_TRY(raft::sparse::detail::cusparsesetpointermode(
handle_ptr->get_cusparse_handle(), CUSPARSE_POINTER_MODE_DEVICE, handle_ptr->get_stream()));
}
// Corresponds to the first good general settings we found
// It's what was used for the GTC results
static void set_Stable1(pdlp_hyper_params::pdlp_hyper_params_t& hyper_params)
{
hyper_params.initial_step_size_scaling = 1.6;
hyper_params.default_l_inf_ruiz_iterations = 1;
hyper_params.do_pock_chambolle_scaling = true;
hyper_params.do_ruiz_scaling = true;
hyper_params.default_alpha_pock_chambolle_rescaling = 1.3;
hyper_params.default_artificial_restart_threshold = 0.5;
hyper_params.compute_initial_step_size_before_scaling = false;
hyper_params.compute_initial_primal_weight_before_scaling = true;
hyper_params.initial_primal_weight_c_scaling = 2.2;
hyper_params.initial_primal_weight_b_scaling = 4.6;
hyper_params.major_iteration = 52;
hyper_params.min_iteration_restart = 0;
hyper_params.restart_strategy = 1;
hyper_params.never_restart_to_average = false;
hyper_params.reduction_exponent = 0.5;
hyper_params.growth_exponent = 0.9;
hyper_params.primal_weight_update_smoothing = 0.3;
hyper_params.sufficient_reduction_for_restart = 0.2;
hyper_params.necessary_reduction_for_restart = 0.5;
hyper_params.primal_importance = 1.8;
hyper_params.primal_distance_smoothing = 0.6;
hyper_params.dual_distance_smoothing = 0.2;
hyper_params.compute_last_restart_before_new_primal_weight = false;
hyper_params.artificial_restart_in_main_loop = false;
hyper_params.rescale_for_restart = false;
hyper_params.update_primal_weight_on_initial_solution = false;
hyper_params.update_step_size_on_initial_solution = false;
hyper_params.handle_some_primal_gradients_on_finite_bounds_as_residuals = true;
hyper_params.project_initial_primal = false;
hyper_params.use_adaptive_step_size_strategy = true;
hyper_params.initial_step_size_max_singular_value = false;
hyper_params.initial_primal_weight_combined_bounds = true;
hyper_params.bound_objective_rescaling = false;
hyper_params.use_reflected_primal_dual = false;
hyper_params.use_fixed_point_error = false;
hyper_params.reflection_coefficient = 1.0; // TODO test with other values
hyper_params.use_conditional_major = false;
}
// Even better general setting due to proper primal gradient handling for KKT restart and initial
// projection
static void set_Stable2(pdlp_hyper_params::pdlp_hyper_params_t& hyper_params)
{
hyper_params.initial_step_size_scaling = 1.0;
hyper_params.default_l_inf_ruiz_iterations = 10;
hyper_params.do_pock_chambolle_scaling = true;
hyper_params.do_ruiz_scaling = true;
hyper_params.default_alpha_pock_chambolle_rescaling = 1.0;
hyper_params.default_artificial_restart_threshold = 0.36;
hyper_params.compute_initial_step_size_before_scaling = false;
hyper_params.compute_initial_primal_weight_before_scaling = false;
hyper_params.initial_primal_weight_c_scaling = 1.0;
hyper_params.initial_primal_weight_b_scaling = 1.0;
hyper_params.major_iteration = 40;
hyper_params.min_iteration_restart = 10;
hyper_params.restart_strategy = 1;
hyper_params.never_restart_to_average = false;
hyper_params.reduction_exponent = 0.3;
hyper_params.growth_exponent = 0.6;
hyper_params.primal_weight_update_smoothing = 0.5;
hyper_params.sufficient_reduction_for_restart = 0.2;
hyper_params.necessary_reduction_for_restart = 0.8;
hyper_params.primal_importance = 1.0;
hyper_params.primal_distance_smoothing = 0.5;
hyper_params.dual_distance_smoothing = 0.5;
hyper_params.compute_last_restart_before_new_primal_weight = true;
hyper_params.artificial_restart_in_main_loop = false;
hyper_params.rescale_for_restart = true;
hyper_params.update_primal_weight_on_initial_solution = false;
hyper_params.update_step_size_on_initial_solution = false;
hyper_params.handle_some_primal_gradients_on_finite_bounds_as_residuals = false;
hyper_params.project_initial_primal = true;
hyper_params.use_adaptive_step_size_strategy = true;
hyper_params.initial_step_size_max_singular_value = false;
hyper_params.initial_primal_weight_combined_bounds = true;
hyper_params.bound_objective_rescaling = false;
hyper_params.use_reflected_primal_dual = false;
hyper_params.use_fixed_point_error = false;
hyper_params.reflection_coefficient = 1.0;
hyper_params.use_conditional_major = false;
}
/* 1 - 1 mapping of cuPDLPx(+) function from Haihao and al.
* For more information please read:
* @article{lu2025cupdlpx,
* title={cuPDLPx: A Further Enhanced GPU-Based First-Order Solver for Linear Programming},
* author={Lu, Haihao and Peng, Zedong and Yang, Jinwen},
* journal={arXiv preprint arXiv:2507.14051},
* year={2025}
* }
*
* @article{lu2024restarted,
* title={Restarted Halpern PDHG for linear programming},
* author={Lu, Haihao and Yang, Jinwen},
* journal={arXiv preprint arXiv:2407.16144},
* year={2024}
* }
*/
static void set_Stable3(pdlp_hyper_params::pdlp_hyper_params_t& hyper_params)
{
hyper_params.initial_step_size_scaling = 1.0;
hyper_params.default_l_inf_ruiz_iterations = 10;
hyper_params.do_pock_chambolle_scaling = true;
hyper_params.do_ruiz_scaling = true;
hyper_params.default_alpha_pock_chambolle_rescaling = 1.0;
hyper_params.default_artificial_restart_threshold = 0.36;
hyper_params.compute_initial_step_size_before_scaling = false;
hyper_params.compute_initial_primal_weight_before_scaling =
true; // TODO this is maybe why he disabled primal weight when bound rescaling is on, because
// TODO try with false
hyper_params.initial_primal_weight_c_scaling = 1.0;
hyper_params.initial_primal_weight_b_scaling = 1.0;
hyper_params.major_iteration = 200; // TODO Try with something smaller
hyper_params.min_iteration_restart = 0;
hyper_params.restart_strategy = 3;
hyper_params.never_restart_to_average = true;
hyper_params.reduction_exponent = 0.3;
hyper_params.growth_exponent = 0.6;
hyper_params.primal_weight_update_smoothing = 0.5;
hyper_params.sufficient_reduction_for_restart = 0.2;
hyper_params.necessary_reduction_for_restart = 0.8;
hyper_params.primal_importance = 1.0;
hyper_params.primal_distance_smoothing = 0.5;
hyper_params.dual_distance_smoothing = 0.5;
hyper_params.compute_last_restart_before_new_primal_weight = true;
hyper_params.artificial_restart_in_main_loop = false;
hyper_params.rescale_for_restart = true;
hyper_params.update_primal_weight_on_initial_solution = false;
hyper_params.update_step_size_on_initial_solution = false;
hyper_params.handle_some_primal_gradients_on_finite_bounds_as_residuals = false;
hyper_params.project_initial_primal = true; // TODO I think he doesn't do it anymore
hyper_params.use_adaptive_step_size_strategy = false;
hyper_params.initial_step_size_max_singular_value = true;
hyper_params.initial_primal_weight_combined_bounds = false;
hyper_params.bound_objective_rescaling = true;
hyper_params.use_reflected_primal_dual = true;
hyper_params.use_fixed_point_error = true;
hyper_params.use_conditional_major = true;
}
// Legacy/Original/Initial PDLP settings
static void set_Methodical1(pdlp_hyper_params::pdlp_hyper_params_t& hyper_params)
{
hyper_params.initial_step_size_scaling = 1.0;
hyper_params.default_l_inf_ruiz_iterations = 5;
hyper_params.do_pock_chambolle_scaling = true;
hyper_params.do_ruiz_scaling = true;
hyper_params.default_alpha_pock_chambolle_rescaling = 1.0;
hyper_params.default_artificial_restart_threshold = 0.5;
hyper_params.compute_initial_step_size_before_scaling = false;
hyper_params.compute_initial_primal_weight_before_scaling = false;
hyper_params.initial_primal_weight_c_scaling = 1.0;
hyper_params.initial_primal_weight_b_scaling = 1.0;
hyper_params.major_iteration = 64;
hyper_params.min_iteration_restart = 0;
hyper_params.restart_strategy = 2;
hyper_params.never_restart_to_average = false;
hyper_params.reduction_exponent = 0.3;
hyper_params.growth_exponent = 0.6;
hyper_params.primal_weight_update_smoothing = 0.5;
hyper_params.sufficient_reduction_for_restart = 0.1;
hyper_params.necessary_reduction_for_restart = 0.9;
hyper_params.primal_importance = 1.0;
hyper_params.primal_distance_smoothing = 0.5;
hyper_params.dual_distance_smoothing = 0.5;
hyper_params.compute_last_restart_before_new_primal_weight = true;
hyper_params.artificial_restart_in_main_loop = false;
hyper_params.rescale_for_restart = false;
hyper_params.update_primal_weight_on_initial_solution = false;
hyper_params.update_step_size_on_initial_solution = false;
hyper_params.handle_some_primal_gradients_on_finite_bounds_as_residuals = true;
hyper_params.project_initial_primal = false;
hyper_params.use_adaptive_step_size_strategy = true;
hyper_params.initial_step_size_max_singular_value = false;
hyper_params.initial_primal_weight_combined_bounds = true;
hyper_params.bound_objective_rescaling = false;
hyper_params.use_reflected_primal_dual = false;
hyper_params.use_fixed_point_error = false;
hyper_params.reflection_coefficient = 1.0;
hyper_params.use_conditional_major = false;
}
// Can be extremly faster but usually leads to more divergence
// Used for the blog post results
static void set_Fast1(pdlp_hyper_params::pdlp_hyper_params_t& hyper_params)
{
hyper_params.initial_step_size_scaling = 0.8;
hyper_params.default_l_inf_ruiz_iterations = 6;
hyper_params.do_pock_chambolle_scaling = true;
hyper_params.do_ruiz_scaling = false;
hyper_params.default_alpha_pock_chambolle_rescaling = 2.0;
hyper_params.default_artificial_restart_threshold = 0.3;
hyper_params.compute_initial_step_size_before_scaling = false;
hyper_params.compute_initial_primal_weight_before_scaling = true;
hyper_params.initial_primal_weight_c_scaling = 1.2;
hyper_params.initial_primal_weight_b_scaling = 1.2;
hyper_params.major_iteration = 76;
hyper_params.min_iteration_restart = 6;
hyper_params.restart_strategy = 1;
hyper_params.never_restart_to_average = true;
hyper_params.reduction_exponent = 0.4;
hyper_params.growth_exponent = 0.6;
hyper_params.primal_weight_update_smoothing = 0.5;
hyper_params.sufficient_reduction_for_restart = 0.3;
hyper_params.necessary_reduction_for_restart = 0.9;
hyper_params.primal_importance = 0.8;
hyper_params.primal_distance_smoothing = 0.8;
hyper_params.dual_distance_smoothing = 0.3;
hyper_params.compute_last_restart_before_new_primal_weight = true;
hyper_params.artificial_restart_in_main_loop = true;
hyper_params.rescale_for_restart = true;
hyper_params.update_primal_weight_on_initial_solution = false;
hyper_params.update_step_size_on_initial_solution = false;
hyper_params.handle_some_primal_gradients_on_finite_bounds_as_residuals = true;
hyper_params.project_initial_primal = false;
hyper_params.use_adaptive_step_size_strategy = true;
hyper_params.initial_step_size_max_singular_value = false;
hyper_params.initial_primal_weight_combined_bounds = true;
hyper_params.bound_objective_rescaling = false;
hyper_params.use_reflected_primal_dual = false;
hyper_params.use_fixed_point_error = false;
hyper_params.reflection_coefficient = 1.0;
hyper_params.use_conditional_major = false;
}
template <typename i_t, typename f_t>
void set_pdlp_solver_mode(pdlp_solver_settings_t<i_t, f_t>& settings)
{
if (settings.pdlp_solver_mode == pdlp_solver_mode_t::Stable2)
set_Stable2(settings.hyper_params);
else if (settings.pdlp_solver_mode == pdlp_solver_mode_t::Stable1)
set_Stable1(settings.hyper_params);
else if (settings.pdlp_solver_mode == pdlp_solver_mode_t::Methodical1)
set_Methodical1(settings.hyper_params);
else if (settings.pdlp_solver_mode == pdlp_solver_mode_t::Fast1)
set_Fast1(settings.hyper_params);
else if (settings.pdlp_solver_mode == pdlp_solver_mode_t::Stable3)
set_Stable3(settings.hyper_params);
}
std::atomic<int> global_concurrent_halt{0};
template <typename f_t>
void adjust_dual_solution_and_reduced_cost(rmm::device_uvector<f_t>& dual_solution,
rmm::device_uvector<f_t>& reduced_cost,
rmm::cuda_stream_view stream_view)
{
// y <- -y
cub::DeviceTransform::Transform(
dual_solution.data(),
dual_solution.data(),
dual_solution.size(),
[] HD(f_t dual) { return -dual; },
stream_view);
// z <- -z
cub::DeviceTransform::Transform(
reduced_cost.data(),
reduced_cost.data(),
reduced_cost.size(),
[] HD(f_t reduced_cost) { return -reduced_cost; },
stream_view);
}
template <typename i_t, typename f_t>
optimization_problem_solution_t<i_t, f_t> convert_dual_simplex_sol(
const dual_simplex::lp_solution_t<i_t, f_t>& solution,
raft::handle_t const* handle_ptr,
std::string const& objective_name,
std::vector<std::string> const& var_names,
std::vector<std::string> const& row_names,
bool maximize,
dual_simplex::lp_status_t status,
f_t duration,
f_t norm_user_objective,
f_t norm_rhs,
method_t method)
{
auto to_termination_status = [](dual_simplex::lp_status_t status) {
switch (status) {
case dual_simplex::lp_status_t::OPTIMAL: return pdlp_termination_status_t::Optimal;
case dual_simplex::lp_status_t::INFEASIBLE:
return pdlp_termination_status_t::PrimalInfeasible;
case dual_simplex::lp_status_t::UNBOUNDED: return pdlp_termination_status_t::DualInfeasible;
case dual_simplex::lp_status_t::TIME_LIMIT: return pdlp_termination_status_t::TimeLimit;
case dual_simplex::lp_status_t::ITERATION_LIMIT:
return pdlp_termination_status_t::IterationLimit;
case dual_simplex::lp_status_t::CONCURRENT_LIMIT:
return pdlp_termination_status_t::ConcurrentLimit;
case dual_simplex::lp_status_t::UNBOUNDED_OR_INFEASIBLE:
return pdlp_termination_status_t::UnboundedOrInfeasible;
default: return pdlp_termination_status_t::NumericalError;
}
};
rmm::device_uvector<f_t> final_primal_solution =
cuopt::device_copy(solution.x, handle_ptr->get_stream());
rmm::device_uvector<f_t> final_dual_solution =
cuopt::device_copy(solution.y, handle_ptr->get_stream());
rmm::device_uvector<f_t> final_reduced_cost =
cuopt::device_copy(solution.z, handle_ptr->get_stream());
handle_ptr->sync_stream();
// Negate dual variables and reduced costs for maximization problems
if (maximize) {
adjust_dual_solution_and_reduced_cost(
final_dual_solution, final_reduced_cost, handle_ptr->get_stream());
handle_ptr->sync_stream();
}
// Should be filled with more information from dual simplex
std::vector<
typename optimization_problem_solution_t<i_t, f_t>::additional_termination_information_t>
info(1);
info[0].solved_by = method;
info[0].primal_objective = solution.user_objective;
info[0].dual_objective = solution.user_objective;
info[0].gap = 0.0;
info[0].relative_gap = 0.0;
info[0].solve_time = duration;
info[0].number_of_steps_taken = solution.iterations;
info[0].total_number_of_attempted_steps = solution.iterations;
info[0].l2_primal_residual = solution.l2_primal_residual;
info[0].l2_dual_residual = solution.l2_dual_residual;
info[0].l2_relative_primal_residual = solution.l2_primal_residual / (1.0 + norm_user_objective);
info[0].l2_relative_dual_residual = solution.l2_dual_residual / (1.0 + norm_rhs);
info[0].max_primal_ray_infeasibility = 0.0;
info[0].primal_ray_linear_objective = 0.0;
info[0].max_dual_ray_infeasibility = 0.0;
info[0].dual_ray_linear_objective = 0.0;
pdlp_termination_status_t termination_status = to_termination_status(status);
auto sol = optimization_problem_solution_t<i_t, f_t>(final_primal_solution,
final_dual_solution,
final_reduced_cost,
objective_name,
var_names,
row_names,
std::move(info),
{termination_status});
if (termination_status != pdlp_termination_status_t::Optimal &&
termination_status != pdlp_termination_status_t::TimeLimit &&
termination_status != pdlp_termination_status_t::ConcurrentLimit) {
CUOPT_LOG_INFO("%s Solve status %s",
method == method_t::DualSimplex ? "Dual Simplex" : "Barrier",
sol.get_termination_status_string().c_str());
}
handle_ptr->sync_stream();
return sol;
}
template <typename i_t, typename f_t>
optimization_problem_solution_t<i_t, f_t> convert_dual_simplex_sol(
detail::problem_t<i_t, f_t>& problem,
const dual_simplex::lp_solution_t<i_t, f_t>& solution,
dual_simplex::lp_status_t status,
f_t duration,
f_t norm_user_objective,
f_t norm_rhs,
method_t method)
{
return convert_dual_simplex_sol(solution,
problem.handle_ptr,
problem.objective_name,
problem.var_names,
problem.row_names,
problem.maximize,
status,
duration,
norm_user_objective,
norm_rhs,
method);
}
template <typename i_t, typename f_t>
optimization_problem_solution_t<i_t, f_t> convert_dual_simplex_sol(
optimization_problem_t<i_t, f_t>& op_problem,
const dual_simplex::lp_solution_t<i_t, f_t>& solution,
dual_simplex::lp_status_t status,
f_t duration,
f_t norm_user_objective,
f_t norm_rhs,
method_t method)
{
return convert_dual_simplex_sol(solution,
op_problem.get_handle_ptr(),
op_problem.get_objective_name(),
op_problem.get_variable_names(),
op_problem.get_row_names(),
op_problem.get_sense(),
status,
duration,
norm_user_objective,
norm_rhs,
method);
}
template <typename i_t, typename f_t>
std::tuple<dual_simplex::lp_solution_t<i_t, f_t>, dual_simplex::lp_status_t, f_t, f_t, f_t>
run_barrier(dual_simplex::user_problem_t<i_t, f_t>& user_problem,
pdlp_solver_settings_t<i_t, f_t> const& settings,
const timer_t& timer)
{
f_t norm_user_objective = dual_simplex::vector_norm2<i_t, f_t>(user_problem.objective);
f_t norm_rhs = dual_simplex::vector_norm2<i_t, f_t>(user_problem.rhs);
dual_simplex::simplex_solver_settings_t<i_t, f_t> barrier_settings;
barrier_settings.num_gpus = settings.num_gpus;
barrier_settings.time_limit = settings.time_limit;
barrier_settings.iteration_limit = settings.iteration_limit;
barrier_settings.concurrent_halt = settings.concurrent_halt;
barrier_settings.folding = settings.folding;
barrier_settings.augmented = settings.augmented;
barrier_settings.dualize = settings.dualize;
barrier_settings.ordering = settings.ordering;
barrier_settings.barrier_dual_initial_point = settings.barrier_dual_initial_point;
barrier_settings.barrier = true;
barrier_settings.crossover = settings.crossover;
barrier_settings.eliminate_dense_columns = settings.eliminate_dense_columns;
barrier_settings.barrier_iterative_refinement = settings.barrier_iterative_refinement;
barrier_settings.barrier_step_scale = settings.barrier_step_scale;
barrier_settings.cudss_deterministic = settings.cudss_deterministic;
barrier_settings.barrier_relaxed_feasibility_tol = settings.tolerances.relative_primal_tolerance;
barrier_settings.barrier_relaxed_optimality_tol = settings.tolerances.relative_dual_tolerance;
barrier_settings.barrier_relaxed_complementarity_tol = settings.tolerances.relative_gap_tolerance;
if (barrier_settings.concurrent_halt != nullptr) {
// Don't show the barrier log in concurrent mode. Show the PDLP log instead
barrier_settings.log.log = false;
}
dual_simplex::lp_solution_t<i_t, f_t> solution(user_problem.num_rows, user_problem.num_cols);
auto status = dual_simplex::solve_linear_program_with_barrier<i_t, f_t>(
user_problem, barrier_settings, timer.get_tic_start(), solution);
CUOPT_LOG_CONDITIONAL_INFO(
!settings.inside_mip, "Barrier finished in %.2f seconds", timer.elapsed_time());
if (settings.concurrent_halt != nullptr &&
(status == dual_simplex::lp_status_t::OPTIMAL ||
status == dual_simplex::lp_status_t::UNBOUNDED ||
status == dual_simplex::lp_status_t::INFEASIBLE ||
status == dual_simplex::lp_status_t::UNBOUNDED_OR_INFEASIBLE)) {
// We finished. Tell PDLP to stop if it is still running.
*settings.concurrent_halt = 1;
}
return {std::move(solution), status, timer.elapsed_time(), norm_user_objective, norm_rhs};
}
template <typename i_t, typename f_t>
optimization_problem_solution_t<i_t, f_t> run_barrier(
detail::problem_t<i_t, f_t>& problem,
pdlp_solver_settings_t<i_t, f_t> const& settings,
const timer_t& timer)
{
// Convert data structures to dual simplex format and back
dual_simplex::user_problem_t<i_t, f_t> dual_simplex_problem =
cuopt_problem_to_user_problem<i_t, f_t>(problem.handle_ptr, problem);
auto sol_dual_simplex = run_barrier(dual_simplex_problem, settings, timer);
return convert_dual_simplex_sol(problem,
std::get<0>(sol_dual_simplex),
std::get<1>(sol_dual_simplex),
std::get<2>(sol_dual_simplex),
std::get<3>(sol_dual_simplex),
std::get<4>(sol_dual_simplex),
method_t::Barrier);
}
template <typename i_t, typename f_t>
void run_barrier_thread(
dual_simplex::user_problem_t<i_t, f_t>& problem,
pdlp_solver_settings_t<i_t, f_t> const& settings,
std::unique_ptr<
std::tuple<dual_simplex::lp_solution_t<i_t, f_t>, dual_simplex::lp_status_t, f_t, f_t, f_t>>&
sol_ptr,
const timer_t& timer)
{
// We will return the solution from the thread as a unique_ptr
sol_ptr = std::make_unique<
std::tuple<dual_simplex::lp_solution_t<i_t, f_t>, dual_simplex::lp_status_t, f_t, f_t, f_t>>(
run_barrier(problem, settings, timer));
// Wait for barrier thread to finish
problem.handle_ptr->sync_stream();
}
template <typename i_t, typename f_t>
std::tuple<dual_simplex::lp_solution_t<i_t, f_t>, dual_simplex::lp_status_t, f_t, f_t, f_t>
run_dual_simplex(dual_simplex::user_problem_t<i_t, f_t>& user_problem,
pdlp_solver_settings_t<i_t, f_t> const& settings,
const timer_t& timer)
{
f_t norm_user_objective = dual_simplex::vector_norm2<i_t, f_t>(user_problem.objective);
f_t norm_rhs = dual_simplex::vector_norm2<i_t, f_t>(user_problem.rhs);
dual_simplex::simplex_solver_settings_t<i_t, f_t> dual_simplex_settings;
dual_simplex_settings.time_limit = settings.time_limit;
dual_simplex_settings.iteration_limit = settings.iteration_limit;
dual_simplex_settings.concurrent_halt = settings.concurrent_halt;
if (dual_simplex_settings.concurrent_halt != nullptr) {
// Don't show the dual simplex log in concurrent mode. Show the PDLP log instead
dual_simplex_settings.log.log = false;
}
dual_simplex::lp_solution_t<i_t, f_t> solution(user_problem.num_rows, user_problem.num_cols);
auto status = dual_simplex::solve_linear_program<i_t, f_t>(
user_problem, dual_simplex_settings, timer.get_tic_start(), solution);
CUOPT_LOG_CONDITIONAL_INFO(
!settings.inside_mip, "Dual simplex finished in %.2f seconds", timer.elapsed_time());
if (settings.concurrent_halt != nullptr &&
(status == dual_simplex::lp_status_t::OPTIMAL ||
status == dual_simplex::lp_status_t::UNBOUNDED ||
status == dual_simplex::lp_status_t::INFEASIBLE ||
status == dual_simplex::lp_status_t::UNBOUNDED_OR_INFEASIBLE)) {
// We finished. Tell PDLP to stop if it is still running.
*settings.concurrent_halt = 1;
}
return {std::move(solution), status, timer.elapsed_time(), norm_user_objective, norm_rhs};
}
template <typename i_t, typename f_t>
optimization_problem_solution_t<i_t, f_t> run_dual_simplex(
detail::problem_t<i_t, f_t>& problem,
pdlp_solver_settings_t<i_t, f_t> const& settings,
const timer_t& timer)
{
// Convert data structures to dual simplex format and back
dual_simplex::user_problem_t<i_t, f_t> dual_simplex_problem =
cuopt_problem_to_user_problem<i_t, f_t>(problem.handle_ptr, problem);
auto sol_dual_simplex = run_dual_simplex(dual_simplex_problem, settings, timer);
return convert_dual_simplex_sol(problem,
std::get<0>(sol_dual_simplex),
std::get<1>(sol_dual_simplex),
std::get<2>(sol_dual_simplex),
std::get<3>(sol_dual_simplex),
std::get<4>(sol_dual_simplex),
method_t::DualSimplex);
}
#if PDLP_INSTANTIATE_FLOAT || CUOPT_INSTANTIATE_FLOAT
template <typename i_t>
static optimization_problem_solution_t<i_t, double> run_pdlp_solver_in_fp32(
detail::problem_t<i_t, double>& problem,
pdlp_solver_settings_t<i_t, double> const& settings,
const timer_t& timer,
bool is_batch_mode)
{
CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "Running PDLP in FP32 precision");
auto stream = problem.handle_ptr->get_stream();
// Convert the optimization problem stored inside problem_t to float
auto float_op = problem.original_problem_ptr->template convert_to_other_prec<float>(stream);
float_op.set_objective_offset(static_cast<float>(problem.presolve_data.objective_offset));
float_op.set_objective_scaling_factor(
static_cast<float>(problem.presolve_data.objective_scaling_factor));
detail::problem_t<i_t, float> float_problem(float_op);
auto objective_name = problem.objective_name;
auto var_names = problem.var_names;
auto row_names = problem.row_names;
// When crossover is off, free double-precision GPU memory to reduce peak usage.
// When crossover is on, run_pdlp needs the problem data after we return.
if (!settings.crossover) {
{
[[maybe_unused]] auto discard = detail::problem_t<i_t, double>(std::move(problem));
}
}
// Create float settings from double settings
pdlp_solver_settings_t<i_t, float> fs;
fs.tolerances.absolute_dual_tolerance =
static_cast<float>(settings.tolerances.absolute_dual_tolerance);
fs.tolerances.relative_dual_tolerance =
static_cast<float>(settings.tolerances.relative_dual_tolerance);
fs.tolerances.absolute_primal_tolerance =
static_cast<float>(settings.tolerances.absolute_primal_tolerance);
fs.tolerances.relative_primal_tolerance =
static_cast<float>(settings.tolerances.relative_primal_tolerance);
fs.tolerances.absolute_gap_tolerance =
static_cast<float>(settings.tolerances.absolute_gap_tolerance);
fs.tolerances.relative_gap_tolerance =
static_cast<float>(settings.tolerances.relative_gap_tolerance);
fs.tolerances.primal_infeasible_tolerance =
static_cast<float>(settings.tolerances.primal_infeasible_tolerance);
fs.tolerances.dual_infeasible_tolerance =
static_cast<float>(settings.tolerances.dual_infeasible_tolerance);
fs.detect_infeasibility = settings.detect_infeasibility;
fs.strict_infeasibility = settings.strict_infeasibility;
fs.iteration_limit = settings.iteration_limit;
fs.time_limit = static_cast<float>(settings.time_limit);
fs.pdlp_solver_mode = settings.pdlp_solver_mode;
fs.log_to_console = settings.log_to_console;
fs.log_file = settings.log_file;
fs.per_constraint_residual = settings.per_constraint_residual;
fs.save_best_primal_so_far = settings.save_best_primal_so_far;
fs.first_primal_feasible = settings.first_primal_feasible;
fs.all_primal_feasible = settings.all_primal_feasible;
fs.eliminate_dense_columns = settings.eliminate_dense_columns;
fs.barrier_iterative_refinement = settings.barrier_iterative_refinement;
fs.barrier_step_scale = settings.barrier_step_scale;
fs.pdlp_precision = pdlp_precision_t::DefaultPrecision;
fs.method = method_t::PDLP;
fs.inside_mip = settings.inside_mip;
fs.hyper_params = settings.hyper_params;
fs.presolver = settings.presolver;
fs.num_gpus = settings.num_gpus;
fs.concurrent_halt = settings.concurrent_halt;
detail::pdlp_solver_t<i_t, float> solver(float_problem, fs, is_batch_mode);
if (settings.inside_mip) { solver.set_inside_mip(true); }
auto float_sol = solver.run_solver(timer);
// Convert float solution back to double on GPU (gpu_cast defined in optimization_problem.cu)
auto dev_primal = gpu_cast<float, double>(float_sol.get_primal_solution(), stream);
auto dev_dual = gpu_cast<float, double>(float_sol.get_dual_solution(), stream);
auto dev_reduced = gpu_cast<float, double>(float_sol.get_reduced_cost(), stream);
// Convert termination info (small host-side struct, stays on CPU)
auto float_term_infos = float_sol.get_additional_termination_informations();
using double_term_info_t =
typename optimization_problem_solution_t<i_t, double>::additional_termination_information_t;
std::vector<double_term_info_t> term_infos;
for (auto& fi : float_term_infos) {
double_term_info_t di;
di.number_of_steps_taken = fi.number_of_steps_taken;
di.total_number_of_attempted_steps = fi.total_number_of_attempted_steps;
di.l2_primal_residual = static_cast<double>(fi.l2_primal_residual);
di.l2_relative_primal_residual = static_cast<double>(fi.l2_relative_primal_residual);
di.l2_dual_residual = static_cast<double>(fi.l2_dual_residual);
di.l2_relative_dual_residual = static_cast<double>(fi.l2_relative_dual_residual);
di.primal_objective = static_cast<double>(fi.primal_objective);
di.dual_objective = static_cast<double>(fi.dual_objective);
di.gap = static_cast<double>(fi.gap);
di.relative_gap = static_cast<double>(fi.relative_gap);
di.max_primal_ray_infeasibility = static_cast<double>(fi.max_primal_ray_infeasibility);
di.primal_ray_linear_objective = static_cast<double>(fi.primal_ray_linear_objective);
di.max_dual_ray_infeasibility = static_cast<double>(fi.max_dual_ray_infeasibility);
di.dual_ray_linear_objective = static_cast<double>(fi.dual_ray_linear_objective);
di.solve_time = fi.solve_time;
di.solved_by = fi.solved_by;
term_infos.push_back(di);
}
auto status_vec = float_sol.get_terminations_status();
return optimization_problem_solution_t<i_t, double>(dev_primal,
dev_dual,
dev_reduced,
objective_name,
var_names,
row_names,
std::move(term_infos),
std::move(status_vec));
}
#endif
template <typename i_t, typename f_t>
static optimization_problem_solution_t<i_t, f_t> run_pdlp_solver(
detail::problem_t<i_t, f_t>& problem,
pdlp_solver_settings_t<i_t, f_t> const& settings,
const timer_t& timer,
bool is_batch_mode)
{
if (problem.n_constraints == 0) {
CUOPT_LOG_CONDITIONAL_INFO(
!settings.inside_mip,
"No constraints in the problem: PDLP can't be run, use Dual Simplex instead.");
return optimization_problem_solution_t<i_t, f_t>{pdlp_termination_status_t::NumericalError,
problem.handle_ptr->get_stream()};
}
#if PDLP_INSTANTIATE_FLOAT || CUOPT_INSTANTIATE_FLOAT
if constexpr (std::is_same_v<f_t, double>) {
if (settings.pdlp_precision == pdlp_precision_t::SinglePrecision) {
return run_pdlp_solver_in_fp32(problem, settings, timer, is_batch_mode);
}
}
#endif
detail::pdlp_solver_t<i_t, f_t> solver(problem, settings, is_batch_mode);
if (settings.inside_mip) { solver.set_inside_mip(true); }
return solver.run_solver(timer);
}
template <typename i_t, typename f_t>
optimization_problem_solution_t<i_t, f_t> run_pdlp(detail::problem_t<i_t, f_t>& problem,
pdlp_solver_settings_t<i_t, f_t> const& settings,
const timer_t& timer,
bool is_batch_mode)
{
if constexpr (!std::is_same_v<f_t, double>) {
cuopt_expects(!is_batch_mode,
error_type_t::ValidationError,
"PDLP batch mode is not supported for float precision. Use double precision.");
}
cuopt_expects(!(settings.pdlp_precision == pdlp_precision_t::MixedPrecision &&
!detail::is_cusparse_runtime_mixed_precision_supported()),
error_type_t::ValidationError,
"Mixed-precision SpMV requires cuSPARSE runtime 12.5 or later.");
cuopt_expects(
!(is_batch_mode && settings.pdlp_precision == pdlp_precision_t::MixedPrecision),
error_type_t::ValidationError,
"Mixed-precision SpMV is not supported in batch mode. Set pdlp_precision=-1 (default) "
"or disable batch mode.");
cuopt_expects(!(settings.pdlp_precision == pdlp_precision_t::SinglePrecision && is_batch_mode),
error_type_t::ValidationError,
"Single-precision PDLP is not supported in batch mode.");
auto start_solver = std::chrono::high_resolution_clock::now();
timer_t timer_pdlp(timer.remaining_time());
auto sol = run_pdlp_solver(problem, settings, timer, is_batch_mode);
// Negate dual variables and reduced costs for maximization problems
if (problem.maximize) {
adjust_dual_solution_and_reduced_cost(
sol.get_dual_solution(), sol.get_reduced_cost(), problem.handle_ptr->get_stream());
problem.handle_ptr->sync_stream();
}
auto pdlp_solve_time = timer_pdlp.elapsed_time();
sol.set_solve_time(timer.elapsed_time());
CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "PDLP finished");
if (sol.get_termination_status() != pdlp_termination_status_t::ConcurrentLimit) {
CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip,
"Status: %s Objective: %.8e Iterations: %d Time: %.3fs",
sol.get_termination_status_string().c_str(),
sol.get_objective_value(),
sol.get_additional_termination_information().number_of_steps_taken,
sol.get_solve_time());
}
if constexpr (std::is_same_v<f_t, double>) {
const bool do_crossover = settings.crossover;
i_t crossover_info = 0;
if (do_crossover && sol.get_termination_status() == pdlp_termination_status_t::Optimal) {
crossover_info = -1;
dual_simplex::lp_problem_t<i_t, f_t> lp(problem.handle_ptr, 1, 1, 1);
dual_simplex::lp_solution_t<i_t, f_t> initial_solution(1, 1);
translate_to_crossover_problem(problem, sol, lp, initial_solution);
dual_simplex::simplex_solver_settings_t<i_t, f_t> dual_simplex_settings;
dual_simplex_settings.time_limit = settings.time_limit;
dual_simplex_settings.iteration_limit = settings.iteration_limit;
dual_simplex_settings.concurrent_halt = settings.concurrent_halt;
dual_simplex::lp_solution_t<i_t, f_t> vertex_solution(lp.num_rows, lp.num_cols);
std::vector<dual_simplex::variable_status_t> vstatus(lp.num_cols);
dual_simplex::crossover_status_t crossover_status =
dual_simplex::crossover(lp,
dual_simplex_settings,
initial_solution,
timer.get_tic_start(),
vertex_solution,
vstatus);
pdlp_termination_status_t termination_status = pdlp_termination_status_t::TimeLimit;
auto to_termination_status = [](dual_simplex::crossover_status_t status) {
switch (status) {
case dual_simplex::crossover_status_t::OPTIMAL: return pdlp_termination_status_t::Optimal;
case dual_simplex::crossover_status_t::PRIMAL_FEASIBLE:
return pdlp_termination_status_t::PrimalFeasible;
case dual_simplex::crossover_status_t::DUAL_FEASIBLE:
return pdlp_termination_status_t::NumericalError;
case dual_simplex::crossover_status_t::NUMERICAL_ISSUES:
return pdlp_termination_status_t::NumericalError;
case dual_simplex::crossover_status_t::CONCURRENT_LIMIT:
return pdlp_termination_status_t::ConcurrentLimit;
case dual_simplex::crossover_status_t::TIME_LIMIT:
return pdlp_termination_status_t::TimeLimit;
default: return pdlp_termination_status_t::NumericalError;
}
};
termination_status = to_termination_status(crossover_status);
if (crossover_status == dual_simplex::crossover_status_t::OPTIMAL) { crossover_info = 0; }
rmm::device_uvector<f_t> final_primal_solution =
cuopt::device_copy(vertex_solution.x, problem.handle_ptr->get_stream());
rmm::device_uvector<f_t> final_dual_solution =
cuopt::device_copy(vertex_solution.y, problem.handle_ptr->get_stream());
rmm::device_uvector<f_t> final_reduced_cost =
cuopt::device_copy(vertex_solution.z, problem.handle_ptr->get_stream());
problem.handle_ptr->sync_stream();
// Negate dual variables and reduced costs for maximization problems
if (problem.maximize) {
adjust_dual_solution_and_reduced_cost(
final_dual_solution, final_reduced_cost, problem.handle_ptr->get_stream());
problem.handle_ptr->sync_stream();
}
// Should be filled with more information from dual simplex
std::vector<
typename optimization_problem_solution_t<i_t, f_t>::additional_termination_information_t>
info(1);
info[0].primal_objective = vertex_solution.user_objective;
info[0].number_of_steps_taken = vertex_solution.iterations;
auto crossover_end = std::chrono::high_resolution_clock::now();
auto crossover_duration =
std::chrono::duration_cast<std::chrono::milliseconds>(crossover_end - start_solver);
info[0].solve_time = crossover_duration.count() / 1000.0;
auto sol_crossover = optimization_problem_solution_t<i_t, f_t>(final_primal_solution,
final_dual_solution,
final_reduced_cost,
problem.objective_name,
problem.var_names,
problem.row_names,
std::move(info),
{termination_status});
sol.copy_from(problem.handle_ptr, sol_crossover);
CUOPT_LOG_CONDITIONAL_INFO(
!settings.inside_mip, "Crossover status %s", sol.get_termination_status_string().c_str());
}
if (settings.method == method_t::Concurrent && settings.concurrent_halt != nullptr &&
crossover_info == 0 && sol.get_termination_status() == pdlp_termination_status_t::Optimal) {
// We finished. Tell dual simplex to stop if it is still running.
CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "PDLP finished. Telling others to stop");
*settings.concurrent_halt = 1;
}
}
return sol;
}
// Compute in double as some cases overflow when using size_t
//
// `per_climber_objectives` / `per_climber_constraint_bounds` tell the estimator whether the caller
// will expand these fields to (trial_batch_size * n_{vars,constraints}).
template <typename i_t, typename f_t>
static double batch_pdlp_memory_estimator(const optimization_problem_t<i_t, f_t>& problem,
double trial_batch_size,
bool per_climber_objectives = false,
bool per_climber_constraint_bounds = false,
bool collect_solutions = false)
{
double total_memory = 0.0;
// In PDLP we store the scaled version of the problem which contains all of those
total_memory += problem.get_constraint_matrix_indices().size() * sizeof(i_t);
total_memory += problem.get_constraint_matrix_offsets().size() * sizeof(i_t);
total_memory += problem.get_constraint_matrix_values().size() * sizeof(f_t);
total_memory *= 2.0; // To account for the A_t matrix
// Internally we always use have a scaled and an unscaled version of the objective coefficients
if (per_climber_objectives) {
total_memory += 2.0 * trial_batch_size * problem.get_n_variables() * sizeof(f_t);
} else {
total_memory += 2.0 * problem.get_objective_coefficients().size() * sizeof(f_t);
}
total_memory += problem.get_constraint_bounds().size() * sizeof(f_t);
total_memory += problem.get_variable_lower_bounds().size() * sizeof(f_t);
total_memory += problem.get_variable_upper_bounds().size() * sizeof(f_t);
// Per-climber constraint bounds expansion adds 2 * trial_batch_size * n_constraints. Strong
// branching never expands these, so the flag guards the cost.
// 2.0 because we have scaled and unscaled
if (per_climber_constraint_bounds) {
total_memory +=
2.0 * trial_batch_size * problem.get_constraint_lower_bounds().size() * sizeof(f_t);
total_memory +=
2.0 * trial_batch_size * problem.get_constraint_upper_bounds().size() * sizeof(f_t);
} else {
total_memory += 2.0 * problem.get_constraint_lower_bounds().size() * sizeof(f_t);
total_memory += 2.0 * problem.get_constraint_upper_bounds().size() * sizeof(f_t);
}
// Batch data estimator
// Data from PDHG
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
// Data from the saddle point state
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
// Data for the convergeance information
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
// Data for the localized duality gap container
total_memory += trial_batch_size * problem.get_n_variables() * sizeof(f_t);
total_memory += trial_batch_size * problem.get_n_constraints() * sizeof(f_t);
// Data for the solution (only allocated when collect_solutions is true)
if (collect_solutions) {
total_memory += problem.get_n_variables() * trial_batch_size * sizeof(f_t);
total_memory += problem.get_n_constraints() * trial_batch_size * sizeof(f_t);
total_memory += problem.get_n_variables() * trial_batch_size * sizeof(f_t);
}
// Add a 70% overhead to make sure we have enough memory considering other parts of the solver may
// need memory later while the batch PDLP is running
total_memory *= 1.7;
// Data from saddle point state
return total_memory;
}
// We need to custom craft a solver settings for the batch mode as we need a specific set of values
// We override iteration limit and pdlp tolerance unless the user has specified otherwise