casadi 3.6.5__cp37-none-manylinux2014_x86_64.whl → 3.6.7__cp37-none-manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (429) hide show
  1. casadi/_casadi.so +0 -0
  2. casadi/casadi.py +739 -308
  3. casadi/cbc +0 -0
  4. casadi/clp +0 -0
  5. casadi/cmake/casadi-config-version.cmake +1 -1
  6. casadi/cmake/highs/highs-config.cmake +6 -13
  7. casadi/cmake/highs/highs-targets-release.cmake +13 -13
  8. casadi/cmake/highs/highs-targets.cmake +13 -10
  9. casadi/highs +0 -0
  10. casadi/include/casadi/casadi.i +3 -0
  11. casadi/include/casadi/casadi_c.h +2 -0
  12. casadi/include/casadi/config.h +8 -8
  13. casadi/include/casadi/core/casadi_common.hpp +1 -0
  14. casadi/include/casadi/core/casadi_misc.hpp +52 -0
  15. casadi/include/casadi/core/casadi_types.hpp +3 -2
  16. casadi/include/casadi/core/code_generator.hpp +30 -1
  17. casadi/include/casadi/core/global_options.hpp +2 -0
  18. casadi/include/casadi/core/mx.hpp +18 -3
  19. casadi/include/casadi/core/optistack.hpp +23 -0
  20. casadi/include/casadi/core/runtime/casadi_nlp.hpp +19 -4
  21. casadi/include/casadi/core/runtime/casadi_ocp_block.hpp +55 -0
  22. casadi/include/casadi/core/runtime/casadi_oracle.hpp +44 -0
  23. casadi/include/casadi/core/runtime/casadi_oracle_callback.hpp +39 -0
  24. casadi/include/casadi/core/runtime/casadi_runtime.hpp +4 -1
  25. casadi/include/casadi/core/runtime/casadi_scaled_copy.hpp +31 -0
  26. casadi/include/casadi/core/serializing_stream.hpp +2 -2
  27. casadi/include/casadi/core/sparsity.hpp +7 -0
  28. casadi/include/casadi/doc.i +1513 -1016
  29. casadi/include/casadi/doc_merged.i +965 -719
  30. casadi/include/casadi/mem.h +1 -0
  31. casadi/include/daqp/api.h +46 -0
  32. casadi/include/daqp/auxiliary.h +29 -0
  33. casadi/include/daqp/bnb.h +32 -0
  34. casadi/include/daqp/codegen.h +18 -0
  35. casadi/include/daqp/constants.h +92 -0
  36. casadi/include/daqp/daqp.h +22 -0
  37. casadi/include/daqp/daqp_prox.h +18 -0
  38. casadi/include/daqp/factorization.h +18 -0
  39. casadi/include/daqp/types.h +161 -0
  40. casadi/include/daqp/utils.h +44 -0
  41. casadi/include/fatrop/auxiliary/Common.hpp +34 -0
  42. casadi/include/fatrop/auxiliary/DynamicLib.hpp +34 -0
  43. casadi/include/fatrop/auxiliary/FatropOptions.hpp +68 -0
  44. casadi/include/fatrop/auxiliary/FatropVector.hpp +143 -0
  45. casadi/include/fatrop/auxiliary/LinearAlgebra.hpp +88 -0
  46. casadi/include/fatrop/auxiliary/VectorUtils.hpp +54 -0
  47. casadi/include/fatrop/blasfeo_wrapper/LinearAlgebraBlasfeo.hpp +493 -0
  48. casadi/include/fatrop/fatrop.hpp +39 -0
  49. casadi/include/fatrop/function_evaluation/CasadiCodegen.hpp +104 -0
  50. casadi/include/fatrop/function_evaluation/FunctionEvaluation.hpp +60 -0
  51. casadi/include/fatrop/json/json.h +946 -0
  52. casadi/include/fatrop/ocp/CasadiCApiUserdataWrap.hpp +87 -0
  53. casadi/include/fatrop/ocp/DuInfEvaluator.hpp +38 -0
  54. casadi/include/fatrop/ocp/FatropOCP.hpp +161 -0
  55. casadi/include/fatrop/ocp/FatropOCPBuilder.hpp +52 -0
  56. casadi/include/fatrop/ocp/FatropOCPResto.hpp +299 -0
  57. casadi/include/fatrop/ocp/OCP.hpp +82 -0
  58. casadi/include/fatrop/ocp/OCPAbstract.hpp +254 -0
  59. casadi/include/fatrop/ocp/OCPAdapter.hpp +197 -0
  60. casadi/include/fatrop/ocp/OCPCInterface.h +289 -0
  61. casadi/include/fatrop/ocp/OCPDims.hpp +60 -0
  62. casadi/include/fatrop/ocp/OCPInitializer.hpp +41 -0
  63. casadi/include/fatrop/ocp/OCPKKT.hpp +69 -0
  64. casadi/include/fatrop/ocp/OCPLSRiccati.hpp +198 -0
  65. casadi/include/fatrop/ocp/OCPLSScaler.hpp +66 -0
  66. casadi/include/fatrop/ocp/OCPLinearSolver.hpp +75 -0
  67. casadi/include/fatrop/ocp/OCPNoScaling.hpp +42 -0
  68. casadi/include/fatrop/ocp/OCPScalingMethod.hpp +42 -0
  69. casadi/include/fatrop/ocp/StageOCP.hpp +592 -0
  70. casadi/include/fatrop/ocp/StageOCPApplication.hpp +242 -0
  71. casadi/include/fatrop/ocp/StageOCPExpressions.hpp +182 -0
  72. casadi/include/fatrop/ocp/UStageEvalAbstract.hpp +168 -0
  73. casadi/include/fatrop/ocp/UStageOCPImpl.hpp +152 -0
  74. casadi/include/fatrop/quasi_newton/bfgs.hpp +159 -0
  75. casadi/include/fatrop/solver/AlgBuilder.hpp +76 -0
  76. casadi/include/fatrop/solver/AlgStrategy.hpp +33 -0
  77. casadi/include/fatrop/solver/FatropAlg.hpp +121 -0
  78. casadi/include/fatrop/solver/FatropData.hpp +188 -0
  79. casadi/include/fatrop/solver/FatropOptions.hpp +95 -0
  80. casadi/include/fatrop/solver/FatropPrinter.hpp +65 -0
  81. casadi/include/fatrop/solver/FatropStats.hpp +63 -0
  82. casadi/include/fatrop/solver/Filter.hpp +54 -0
  83. casadi/include/fatrop/solver/IterationData.hpp +56 -0
  84. casadi/include/fatrop/solver/LineSearch.hpp +86 -0
  85. casadi/include/fatrop/solver/NLPL1.hpp +263 -0
  86. casadi/include/fatrop/templates/NLPAlg.hpp +104 -0
  87. casadi/include/highs/HConfig.h +6 -5
  88. casadi/include/highs/Highs.h +93 -23
  89. casadi/include/highs/filereaderlp/def.hpp +19 -0
  90. casadi/include/highs/interfaces/highs_c_api.h +200 -24
  91. casadi/include/highs/io/Filereader.h +1 -1
  92. casadi/include/highs/io/FilereaderEms.h +1 -1
  93. casadi/include/highs/io/FilereaderLp.h +1 -1
  94. casadi/include/highs/io/FilereaderMps.h +1 -1
  95. casadi/include/highs/io/HMPSIO.h +1 -1
  96. casadi/include/highs/io/HMpsFF.h +5 -3
  97. casadi/include/highs/io/HighsIO.h +18 -8
  98. casadi/include/highs/io/LoadOptions.h +1 -1
  99. casadi/include/highs/ipm/IpxSolution.h +35 -0
  100. casadi/include/highs/ipm/IpxWrapper.h +1 -1
  101. casadi/include/highs/ipm/basiclu/basiclu.h +161 -0
  102. casadi/include/highs/ipm/basiclu/basiclu_factorize.h +247 -0
  103. casadi/include/highs/ipm/basiclu/basiclu_get_factors.h +108 -0
  104. casadi/include/highs/ipm/basiclu/basiclu_initialize.h +119 -0
  105. casadi/include/highs/ipm/basiclu/basiclu_obj_factorize.h +34 -0
  106. casadi/include/highs/ipm/basiclu/basiclu_obj_free.h +19 -0
  107. casadi/include/highs/ipm/basiclu/basiclu_obj_get_factors.h +34 -0
  108. casadi/include/highs/ipm/basiclu/basiclu_obj_initialize.h +46 -0
  109. casadi/include/highs/ipm/basiclu/basiclu_obj_solve_dense.h +29 -0
  110. casadi/include/highs/ipm/basiclu/basiclu_obj_solve_for_update.h +42 -0
  111. casadi/include/highs/ipm/basiclu/basiclu_obj_solve_sparse.h +32 -0
  112. casadi/include/highs/ipm/basiclu/basiclu_obj_update.h +31 -0
  113. casadi/include/highs/ipm/basiclu/basiclu_object.h +30 -0
  114. casadi/include/highs/ipm/basiclu/basiclu_solve_dense.h +75 -0
  115. casadi/include/highs/ipm/basiclu/basiclu_solve_for_update.h +169 -0
  116. casadi/include/highs/ipm/basiclu/basiclu_solve_sparse.h +112 -0
  117. casadi/include/highs/ipm/basiclu/basiclu_update.h +125 -0
  118. casadi/include/highs/ipm/basiclu/lu_def.h +39 -0
  119. casadi/include/highs/ipm/basiclu/lu_file.h +21 -0
  120. casadi/include/highs/ipm/basiclu/lu_internal.h +220 -0
  121. casadi/include/highs/ipm/basiclu/lu_list.h +168 -0
  122. casadi/include/highs/ipm/ipx/basiclu_kernel.h +20 -0
  123. casadi/include/highs/ipm/ipx/basiclu_wrapper.h +47 -0
  124. casadi/include/highs/ipm/ipx/basis.h +351 -0
  125. casadi/include/highs/ipm/ipx/conjugate_residuals.h +74 -0
  126. casadi/include/highs/ipm/ipx/control.h +163 -0
  127. casadi/include/highs/ipm/ipx/crossover.h +157 -0
  128. casadi/include/highs/ipm/ipx/diagonal_precond.h +45 -0
  129. casadi/include/highs/ipm/ipx/forrest_tomlin.h +102 -0
  130. casadi/include/highs/ipm/ipx/guess_basis.h +21 -0
  131. casadi/include/highs/ipm/ipx/indexed_vector.h +113 -0
  132. casadi/include/highs/ipm/ipx/info.h +27 -0
  133. casadi/include/highs/ipm/ipx/ipm.h +94 -0
  134. casadi/include/highs/ipm/ipx/ipx_c.h +47 -0
  135. casadi/include/highs/ipm/ipx/ipx_config.h +9 -0
  136. casadi/include/highs/ipm/ipx/ipx_info.h +111 -0
  137. casadi/include/highs/ipm/ipx/ipx_internal.h +88 -0
  138. casadi/include/highs/ipm/ipx/ipx_parameters.h +75 -0
  139. casadi/include/highs/ipm/ipx/ipx_status.h +57 -0
  140. casadi/include/highs/ipm/ipx/iterate.h +328 -0
  141. casadi/include/highs/ipm/ipx/kkt_solver.h +70 -0
  142. casadi/include/highs/ipm/ipx/kkt_solver_basis.h +66 -0
  143. casadi/include/highs/ipm/ipx/kkt_solver_diag.h +48 -0
  144. casadi/include/highs/ipm/ipx/linear_operator.h +26 -0
  145. casadi/include/highs/ipm/ipx/lp_solver.h +201 -0
  146. casadi/include/highs/ipm/ipx/lu_factorization.h +79 -0
  147. casadi/include/highs/ipm/ipx/lu_update.h +129 -0
  148. casadi/include/highs/ipm/ipx/maxvolume.h +54 -0
  149. casadi/include/highs/ipm/ipx/model.h +409 -0
  150. casadi/include/highs/ipm/ipx/multistream.h +52 -0
  151. casadi/include/highs/ipm/ipx/normal_matrix.h +44 -0
  152. casadi/include/highs/ipm/ipx/power_method.h +44 -0
  153. casadi/include/highs/ipm/ipx/sparse_matrix.h +195 -0
  154. casadi/include/highs/ipm/ipx/sparse_utils.h +58 -0
  155. casadi/include/highs/ipm/ipx/splitted_normal_matrix.h +63 -0
  156. casadi/include/highs/ipm/ipx/starting_basis.h +39 -0
  157. casadi/include/highs/ipm/ipx/symbolic_invert.h +29 -0
  158. casadi/include/highs/ipm/ipx/timer.h +24 -0
  159. casadi/include/highs/ipm/ipx/utils.h +39 -0
  160. casadi/include/highs/lp_data/HConst.h +20 -10
  161. casadi/include/highs/lp_data/HStruct.h +23 -1
  162. casadi/include/highs/lp_data/HighsAnalysis.h +1 -1
  163. casadi/include/highs/lp_data/HighsCallback.h +10 -3
  164. casadi/include/highs/lp_data/HighsCallbackStruct.h +31 -5
  165. casadi/include/highs/lp_data/HighsDebug.h +1 -1
  166. casadi/include/highs/lp_data/HighsInfo.h +20 -2
  167. casadi/include/highs/lp_data/HighsInfoDebug.h +1 -1
  168. casadi/include/highs/lp_data/HighsLp.h +17 -1
  169. casadi/include/highs/lp_data/HighsLpSolverObject.h +1 -1
  170. casadi/include/highs/lp_data/HighsLpUtils.h +19 -19
  171. casadi/include/highs/lp_data/HighsModelUtils.h +1 -1
  172. casadi/include/highs/lp_data/HighsOptions.h +237 -10
  173. casadi/include/highs/lp_data/HighsRanging.h +1 -1
  174. casadi/include/highs/lp_data/HighsRuntimeOptions.h +2 -2
  175. casadi/include/highs/lp_data/HighsSolution.h +2 -2
  176. casadi/include/highs/lp_data/HighsSolutionDebug.h +1 -1
  177. casadi/include/highs/lp_data/HighsSolve.h +3 -1
  178. casadi/include/highs/lp_data/HighsStatus.h +1 -1
  179. casadi/include/highs/mip/HighsCliqueTable.h +4 -4
  180. casadi/include/highs/mip/HighsConflictPool.h +1 -1
  181. casadi/include/highs/mip/HighsCutGeneration.h +1 -1
  182. casadi/include/highs/mip/HighsCutPool.h +2 -2
  183. casadi/include/highs/mip/HighsDebugSol.h +22 -29
  184. casadi/include/highs/mip/HighsDomain.h +10 -2
  185. casadi/include/highs/mip/HighsDomainChange.h +1 -1
  186. casadi/include/highs/mip/HighsDynamicRowMatrix.h +5 -3
  187. casadi/include/highs/mip/HighsGFkSolve.h +3 -3
  188. casadi/include/highs/mip/HighsImplications.h +3 -3
  189. casadi/include/highs/mip/HighsLpAggregator.h +1 -1
  190. casadi/include/highs/mip/HighsLpRelaxation.h +6 -1
  191. casadi/include/highs/mip/HighsMipSolver.h +4 -2
  192. casadi/include/highs/mip/HighsMipSolverData.h +47 -4
  193. casadi/include/highs/mip/HighsModkSeparator.h +2 -2
  194. casadi/include/highs/mip/HighsNodeQueue.h +5 -3
  195. casadi/include/highs/mip/HighsObjectiveFunction.h +1 -1
  196. casadi/include/highs/mip/HighsPathSeparator.h +2 -2
  197. casadi/include/highs/mip/HighsPrimalHeuristics.h +1 -1
  198. casadi/include/highs/mip/HighsPseudocost.h +35 -23
  199. casadi/include/highs/mip/HighsRedcostFixing.h +1 -1
  200. casadi/include/highs/mip/HighsSearch.h +2 -1
  201. casadi/include/highs/mip/HighsSeparation.h +1 -1
  202. casadi/include/highs/mip/HighsSeparator.h +1 -1
  203. casadi/include/highs/mip/HighsTableauSeparator.h +1 -1
  204. casadi/include/highs/mip/HighsTransformedLp.h +1 -1
  205. casadi/include/highs/model/HighsHessian.h +5 -0
  206. casadi/include/highs/model/HighsHessianUtils.h +2 -0
  207. casadi/include/highs/model/HighsModel.h +10 -1
  208. casadi/include/highs/parallel/HighsMutex.h +2 -1
  209. casadi/include/highs/parallel/HighsParallel.h +7 -2
  210. casadi/include/highs/parallel/HighsTask.h +1 -2
  211. casadi/include/highs/pdlp/CupdlpWrapper.h +93 -0
  212. casadi/include/highs/pdlp/cupdlp/cupdlp_cs.h +41 -0
  213. casadi/include/highs/pdlp/cupdlp/cupdlp_defs.h +423 -0
  214. casadi/include/highs/pdlp/cupdlp/cupdlp_linalg.h +183 -0
  215. casadi/include/highs/pdlp/cupdlp/cupdlp_proj.h +19 -0
  216. casadi/include/highs/pdlp/cupdlp/cupdlp_restart.h +31 -0
  217. casadi/include/highs/pdlp/cupdlp/cupdlp_scaling_cuda.h +28 -0
  218. casadi/include/highs/pdlp/cupdlp/cupdlp_solver.h +98 -0
  219. casadi/include/highs/pdlp/cupdlp/cupdlp_step.h +33 -0
  220. casadi/include/highs/pdlp/cupdlp/cupdlp_utils.c +1726 -0
  221. casadi/include/highs/pdqsort/pdqsort.h +532 -0
  222. casadi/include/highs/presolve/HPresolve.h +27 -14
  223. casadi/include/highs/presolve/HPresolveAnalysis.h +1 -1
  224. casadi/include/highs/presolve/HighsPostsolveStack.h +92 -68
  225. casadi/include/highs/presolve/HighsSymmetry.h +6 -5
  226. casadi/include/highs/presolve/ICrash.h +8 -2
  227. casadi/include/highs/presolve/ICrashUtil.h +1 -1
  228. casadi/include/highs/presolve/ICrashX.h +1 -1
  229. casadi/include/highs/presolve/PresolveComponent.h +1 -1
  230. casadi/include/highs/qpsolver/a_asm.hpp +23 -12
  231. casadi/include/highs/qpsolver/a_quass.hpp +8 -1
  232. casadi/include/highs/qpsolver/basis.hpp +150 -0
  233. casadi/include/highs/qpsolver/crashsolution.hpp +12 -0
  234. casadi/include/highs/qpsolver/dantzigpricing.hpp +72 -0
  235. casadi/include/highs/qpsolver/devexpricing.hpp +99 -0
  236. casadi/include/highs/qpsolver/eventhandler.hpp +23 -0
  237. casadi/include/highs/qpsolver/factor.hpp +400 -0
  238. casadi/include/highs/qpsolver/feasibility_bounded.hpp +105 -0
  239. casadi/include/highs/qpsolver/feasibility_highs.hpp +270 -0
  240. casadi/include/highs/qpsolver/gradient.hpp +39 -0
  241. casadi/include/highs/qpsolver/instance.hpp +63 -0
  242. casadi/include/highs/qpsolver/matrix.hpp +335 -0
  243. casadi/include/highs/qpsolver/pricing.hpp +15 -0
  244. casadi/include/highs/qpsolver/qpconst.hpp +27 -0
  245. casadi/include/highs/qpsolver/{vector.hpp → qpvector.hpp} +25 -25
  246. casadi/include/highs/qpsolver/quass.hpp +1 -1
  247. casadi/include/highs/qpsolver/ratiotest.hpp +19 -0
  248. casadi/include/highs/qpsolver/runtime.hpp +38 -0
  249. casadi/include/highs/qpsolver/settings.hpp +57 -0
  250. casadi/include/highs/qpsolver/snippets.hpp +29 -0
  251. casadi/include/highs/qpsolver/statistics.hpp +23 -0
  252. casadi/include/highs/qpsolver/steepestedgepricing.hpp +167 -0
  253. casadi/include/highs/simplex/HApp.h +1 -1
  254. casadi/include/highs/simplex/HEkk.h +52 -18
  255. casadi/include/highs/simplex/HEkkDual.h +1 -1
  256. casadi/include/highs/simplex/HEkkDualRHS.h +6 -7
  257. casadi/include/highs/simplex/HEkkDualRow.h +2 -2
  258. casadi/include/highs/simplex/HEkkPrimal.h +6 -1
  259. casadi/include/highs/simplex/HSimplex.h +1 -3
  260. casadi/include/highs/simplex/HSimplexDebug.h +1 -1
  261. casadi/include/highs/simplex/HSimplexNla.h +1 -1
  262. casadi/include/highs/simplex/HSimplexReport.h +1 -1
  263. casadi/include/highs/simplex/HighsSimplexAnalysis.h +228 -100
  264. casadi/include/highs/simplex/SimplexConst.h +1 -1
  265. casadi/include/highs/simplex/SimplexStruct.h +2 -2
  266. casadi/include/highs/simplex/SimplexTimer.h +1 -1
  267. casadi/include/highs/test/DevKkt.h +1 -1
  268. casadi/include/highs/test/KktCh2.h +1 -1
  269. casadi/include/highs/util/FactorTimer.h +1 -1
  270. casadi/include/highs/util/HFactor.h +35 -6
  271. casadi/include/highs/util/HFactorConst.h +1 -1
  272. casadi/include/highs/util/HFactorDebug.h +1 -1
  273. casadi/include/highs/util/HSet.h +1 -1
  274. casadi/include/highs/util/HVector.h +1 -1
  275. casadi/include/highs/util/HVectorBase.h +1 -1
  276. casadi/include/highs/util/HighsCDouble.h +3 -3
  277. casadi/include/highs/util/HighsComponent.h +1 -1
  278. casadi/include/highs/util/HighsDataStack.h +4 -4
  279. casadi/include/highs/util/HighsDisjointSets.h +1 -1
  280. casadi/include/highs/util/HighsHash.h +28 -21
  281. casadi/include/highs/util/HighsHashTree.h +63 -63
  282. casadi/include/highs/util/HighsInt.h +1 -1
  283. casadi/include/highs/util/HighsIntegers.h +8 -9
  284. casadi/include/highs/util/HighsLinearSumBounds.h +1 -1
  285. casadi/include/highs/util/HighsMatrixPic.h +1 -1
  286. casadi/include/highs/util/HighsMatrixSlice.h +9 -6
  287. casadi/include/highs/util/HighsMatrixUtils.h +1 -1
  288. casadi/include/highs/util/HighsMemoryAllocation.h +55 -0
  289. casadi/include/highs/util/HighsRandom.h +27 -15
  290. casadi/include/highs/util/HighsRbTree.h +2 -2
  291. casadi/include/highs/util/HighsSort.h +7 -7
  292. casadi/include/highs/util/HighsSparseMatrix.h +5 -2
  293. casadi/include/highs/util/HighsSparseVectorSum.h +2 -2
  294. casadi/include/highs/util/HighsSplay.h +1 -1
  295. casadi/include/highs/util/HighsTimer.h +18 -9
  296. casadi/include/highs/util/HighsUtils.h +15 -8
  297. casadi/include/highs/util/stringutil.h +9 -4
  298. casadi/include/highs/zstr/strict_fstream.hpp +237 -0
  299. casadi/include/highs/zstr/zstr.hpp +472 -0
  300. casadi/include/highs_export.h +42 -0
  301. casadi/include/licenses/daqp-external/LICENSE +21 -0
  302. casadi/include/licenses/fatrop-external/LICENSE.txt +165 -0
  303. casadi/include/licenses/fatrop-external/external/blasfeo/LICENSE.txt +26 -0
  304. casadi/include/licenses/fatrop-external/external/pybind11/LICENSE +29 -0
  305. casadi/include/licenses/highs-external/{LICENSE → LICENSE.txt} +1 -1
  306. casadi/include/osqp/constants.h +2 -3
  307. casadi/include/osqp/version.h +9 -0
  308. casadi/include/sleqp/defs.h +2 -2
  309. casadi/lib64/libtinyxml2.a +0 -0
  310. casadi/libCbcSolver.so +0 -0
  311. casadi/libCbcSolver.so.3 +0 -0
  312. casadi/libCbcSolver.so.3.10.11 +0 -0
  313. casadi/libClpSolver.so +0 -0
  314. casadi/libClpSolver.so.1 +0 -0
  315. casadi/libClpSolver.so.1.14.9 +0 -0
  316. casadi/libbonmin.so +0 -0
  317. casadi/libbonmin.so.4 +0 -0
  318. casadi/libbonmin.so.4.8.9 +0 -0
  319. casadi/libcasadi.so +0 -0
  320. casadi/libcasadi.so.3.7 +0 -0
  321. casadi/libcasadi_conic_cbc.so +0 -0
  322. casadi/libcasadi_conic_cbc.so.3.7 +0 -0
  323. casadi/libcasadi_conic_clp.so +0 -0
  324. casadi/libcasadi_conic_clp.so.3.7 +0 -0
  325. casadi/libcasadi_conic_cplex.so +0 -0
  326. casadi/libcasadi_conic_cplex.so.3.7 +0 -0
  327. casadi/libcasadi_conic_daqp.so +0 -0
  328. casadi/libcasadi_conic_daqp.so.3.7 +0 -0
  329. casadi/libcasadi_conic_fatrop.so +0 -0
  330. casadi/libcasadi_conic_fatrop.so.3.7 +0 -0
  331. casadi/libcasadi_conic_gurobi.so +0 -0
  332. casadi/libcasadi_conic_gurobi.so.3.7 +0 -0
  333. casadi/libcasadi_conic_highs.so +0 -0
  334. casadi/libcasadi_conic_highs.so.3.7 +0 -0
  335. casadi/libcasadi_conic_hpipm.so +0 -0
  336. casadi/libcasadi_conic_hpipm.so.3.7 +0 -0
  337. casadi/libcasadi_conic_ipqp.so +0 -0
  338. casadi/libcasadi_conic_ipqp.so.3.7 +0 -0
  339. casadi/libcasadi_conic_nlpsol.so +0 -0
  340. casadi/libcasadi_conic_nlpsol.so.3.7 +0 -0
  341. casadi/libcasadi_conic_osqp.so +0 -0
  342. casadi/libcasadi_conic_osqp.so.3.7 +0 -0
  343. casadi/libcasadi_conic_proxqp.so +0 -0
  344. casadi/libcasadi_conic_proxqp.so.3.7 +0 -0
  345. casadi/libcasadi_conic_qpoases.so +0 -0
  346. casadi/libcasadi_conic_qpoases.so.3.7 +0 -0
  347. casadi/libcasadi_conic_qrqp.so +0 -0
  348. casadi/libcasadi_conic_qrqp.so.3.7 +0 -0
  349. casadi/libcasadi_conic_superscs.so +0 -0
  350. casadi/libcasadi_conic_superscs.so.3.7 +0 -0
  351. casadi/libcasadi_integrator_collocation.so +0 -0
  352. casadi/libcasadi_integrator_collocation.so.3.7 +0 -0
  353. casadi/libcasadi_integrator_cvodes.so +0 -0
  354. casadi/libcasadi_integrator_cvodes.so.3.7 +0 -0
  355. casadi/libcasadi_integrator_idas.so +0 -0
  356. casadi/libcasadi_integrator_idas.so.3.7 +0 -0
  357. casadi/libcasadi_integrator_rk.so +0 -0
  358. casadi/libcasadi_integrator_rk.so.3.7 +0 -0
  359. casadi/libcasadi_nlpsol_alpaqa.so +0 -0
  360. casadi/libcasadi_nlpsol_alpaqa.so.3.7 +0 -0
  361. casadi/libcasadi_nlpsol_ampl.so +0 -0
  362. casadi/libcasadi_nlpsol_ampl.so.3.7 +0 -0
  363. casadi/libcasadi_nlpsol_blocksqp.so +0 -0
  364. casadi/libcasadi_nlpsol_blocksqp.so.3.7 +0 -0
  365. casadi/libcasadi_nlpsol_bonmin.so +0 -0
  366. casadi/libcasadi_nlpsol_bonmin.so.3.7 +0 -0
  367. casadi/libcasadi_nlpsol_fatrop.so +0 -0
  368. casadi/libcasadi_nlpsol_fatrop.so.3.7 +0 -0
  369. casadi/libcasadi_nlpsol_feasiblesqpmethod.so +0 -0
  370. casadi/libcasadi_nlpsol_feasiblesqpmethod.so.3.7 +0 -0
  371. casadi/libcasadi_nlpsol_ipopt.so +0 -0
  372. casadi/libcasadi_nlpsol_ipopt.so.3.7 +0 -0
  373. casadi/libcasadi_nlpsol_knitro.so +0 -0
  374. casadi/libcasadi_nlpsol_knitro.so.3.7 +0 -0
  375. casadi/libcasadi_nlpsol_madnlp.so +0 -0
  376. casadi/libcasadi_nlpsol_madnlp.so.3.7 +0 -0
  377. casadi/libcasadi_nlpsol_qrsqp.so +0 -0
  378. casadi/libcasadi_nlpsol_qrsqp.so.3.7 +0 -0
  379. casadi/libcasadi_nlpsol_scpgen.so +0 -0
  380. casadi/libcasadi_nlpsol_scpgen.so.3.7 +0 -0
  381. casadi/libcasadi_nlpsol_sleqp.so +0 -0
  382. casadi/libcasadi_nlpsol_sleqp.so.3.7 +0 -0
  383. casadi/libcasadi_nlpsol_snopt.so +0 -0
  384. casadi/libcasadi_nlpsol_snopt.so.3.7 +0 -0
  385. casadi/libcasadi_nlpsol_sqpmethod.so +0 -0
  386. casadi/libcasadi_nlpsol_sqpmethod.so.3.7 +0 -0
  387. casadi/libcasadi_nlpsol_worhp.so +0 -0
  388. casadi/libcasadi_nlpsol_worhp.so.3.7 +0 -0
  389. casadi/libcasadi_rootfinder_fast_newton.so +0 -0
  390. casadi/libcasadi_rootfinder_fast_newton.so.3.7 +0 -0
  391. casadi/libcasadi_rootfinder_kinsol.so +0 -0
  392. casadi/libcasadi_rootfinder_kinsol.so.3.7 +0 -0
  393. casadi/libcasadi_rootfinder_newton.so +0 -0
  394. casadi/libcasadi_rootfinder_newton.so.3.7 +0 -0
  395. casadi/libcasadi_rootfinder_nlpsol.so +0 -0
  396. casadi/libcasadi_rootfinder_nlpsol.so.3.7 +0 -0
  397. casadi/libcasadi_sundials_common.so +0 -0
  398. casadi/libcasadi_sundials_common.so.3.7 +0 -0
  399. casadi/libcoinmetis.la +1 -1
  400. casadi/libcoinmetis.so +0 -0
  401. casadi/libcoinmetis.so.2 +0 -0
  402. casadi/libcoinmetis.so.2.0.0 +0 -0
  403. casadi/libdaqp.so +0 -0
  404. casadi/libdaqpstat.a +0 -0
  405. casadi/libfatrop.so +0 -0
  406. casadi/libhighs.so +0 -0
  407. casadi/libhighs.so.1 +0 -0
  408. casadi/libhighs.so.1.7.2 +0 -0
  409. casadi/libindirect.a +0 -0
  410. casadi/liblinsys.a +0 -0
  411. casadi/libmatlab_ipc.so +0 -0
  412. casadi/libosqp.a +0 -0
  413. casadi/libosqp.so +0 -0
  414. casadi/libqdldl.a +0 -0
  415. casadi/libsleqp.so +0 -0
  416. casadi/libsleqp.so.1.0.1 +0 -0
  417. casadi/libspral.a +0 -0
  418. casadi/libsuperscs.a +0 -0
  419. casadi/pkgconfig/casadi.pc +1 -1
  420. casadi/pkgconfig/highs.pc +1 -1
  421. casadi/tools/__init__.py +4 -0
  422. casadi/tools/bounds.py +3 -3
  423. {casadi-3.6.5.dist-info → casadi-3.6.7.dist-info}/METADATA +2 -2
  424. {casadi-3.6.5.dist-info → casadi-3.6.7.dist-info}/RECORD +425 -255
  425. casadi/include/highs/fortran/highs_fortran_api.mod +0 -0
  426. casadi/libFortranHighs.so +0 -0
  427. casadi/libhighs.so.1.6 +0 -0
  428. casadi/libhighs.so.1.6.0 +0 -0
  429. {casadi-3.6.5.dist-info → casadi-3.6.7.dist-info}/WHEEL +0 -0
@@ -0,0 +1,1726 @@
1
+ //
2
+ // Created by chuwen on 23-11-26.
3
+ //
4
+
5
+ #include "cupdlp_utils.h"
6
+
7
+ #include <limits.h>
8
+ #include <stdio.h>
9
+
10
+ #include <time.h>
11
+
12
+ #include "cupdlp_cs.h"
13
+ #include "cupdlp_linalg.h"
14
+ #include "glbopts.h"
15
+
16
+ #ifndef CUPDLP_CPU
17
+
18
+ #include "cuda/cupdlp_cudalinalg.cuh"
19
+
20
+ #endif
21
+
22
+ void dense_clear(CUPDLPdense *dense) {
23
+ if (dense) {
24
+ if (dense->data) {
25
+ cupdlp_free(dense->data);
26
+ }
27
+ cupdlp_free(dense);
28
+ }
29
+ }
30
+
31
+ cupdlp_int csc_clear(CUPDLPcsc *csc) {
32
+ if (csc) {
33
+ #ifndef CUPDLP_CPU
34
+ if (csc->cuda_csc != NULL) {
35
+ CHECK_CUSPARSE(cusparseDestroySpMat(csc->cuda_csc))
36
+ }
37
+ #endif
38
+ if (csc->colMatBeg) {
39
+ CUPDLP_FREE_VEC(csc->colMatBeg);
40
+ }
41
+ if (csc->colMatIdx) {
42
+ CUPDLP_FREE_VEC(csc->colMatIdx);
43
+ }
44
+ if (csc->colMatElem) {
45
+ CUPDLP_FREE_VEC(csc->colMatElem);
46
+ }
47
+ CUPDLP_FREE_VEC(csc);
48
+ }
49
+ return 0;
50
+ }
51
+
52
+ cupdlp_int csr_clear(CUPDLPcsr *csr) {
53
+ if (csr) {
54
+ #ifndef CUPDLP_CPU
55
+ if (csr->cuda_csr != NULL) {
56
+ CHECK_CUSPARSE(cusparseDestroySpMat(csr->cuda_csr))
57
+ }
58
+ #endif
59
+ if (csr->rowMatBeg) {
60
+ CUPDLP_FREE_VEC(csr->rowMatBeg);
61
+ }
62
+ if (csr->rowMatIdx) {
63
+ CUPDLP_FREE_VEC(csr->rowMatIdx);
64
+ }
65
+ if (csr->rowMatElem) {
66
+ CUPDLP_FREE_VEC(csr->rowMatElem);
67
+ }
68
+ CUPDLP_FREE_VEC(csr);
69
+ }
70
+ return 0;
71
+ }
72
+
73
+ void data_clear(CUPDLPdata *data) {
74
+ if (data) {
75
+ switch (data->matrix_format) {
76
+ case DENSE:
77
+ dense_clear(data->dense_matrix);
78
+ break;
79
+ case CSR:
80
+ csr_clear(data->csr_matrix);
81
+ break;
82
+ case CSC:
83
+ csc_clear(data->csc_matrix);
84
+ break;
85
+ case CSR_CSC:
86
+ csr_clear(data->csr_matrix);
87
+ csc_clear(data->csc_matrix);
88
+ break;
89
+ }
90
+ cupdlp_free(data);
91
+ }
92
+ }
93
+
94
+ void problem_clear(CUPDLPproblem *problem) {
95
+ if (problem) {
96
+ if (problem->data) {
97
+ data_clear(problem->data);
98
+ }
99
+ // if (problem->colMatBeg) {
100
+ // cupdlp_free(problem->colMatBeg);
101
+ // }
102
+ // if (problem->colMatIdx) {
103
+ // cupdlp_free(problem->colMatIdx);
104
+ // }
105
+ // if (problem->colMatElem) {
106
+ // cupdlp_free(problem->colMatElem);
107
+ // }
108
+ // if (problem->rowMatBeg) {
109
+ // cupdlp_free(problem->rowMatBeg);
110
+ // }
111
+ // if (problem->rowMatIdx) {
112
+ // cupdlp_free(problem->rowMatIdx);
113
+ // }
114
+ // if (problem->rowMatElem) {
115
+ // cupdlp_free(problem->rowMatElem);
116
+ // }
117
+ if (problem->lower) {
118
+ CUPDLP_FREE_VEC(problem->lower);
119
+ }
120
+ if (problem->upper) {
121
+ CUPDLP_FREE_VEC(problem->upper);
122
+ }
123
+ if (problem->cost) {
124
+ CUPDLP_FREE_VEC(problem->cost);
125
+ }
126
+ if (problem->rhs) {
127
+ CUPDLP_FREE_VEC(problem->rhs);
128
+ }
129
+ if (problem->hasLower) {
130
+ CUPDLP_FREE_VEC(problem->hasLower);
131
+ }
132
+ if (problem->hasUpper) {
133
+ CUPDLP_FREE_VEC(problem->hasUpper);
134
+ }
135
+ CUPDLP_FREE_VEC(problem);
136
+ }
137
+ }
138
+
139
+ void settings_clear(CUPDLPsettings *settings) {
140
+ if (settings) {
141
+ cupdlp_free(settings);
142
+ }
143
+ }
144
+
145
+ cupdlp_int vec_clear(CUPDLPvec *vec) {
146
+ if (vec) {
147
+ if (vec->data) {
148
+ CUPDLP_FREE_VEC(vec->data);
149
+ }
150
+ #ifndef CUPDLP_CPU
151
+ CHECK_CUSPARSE(cusparseDestroyDnVec(vec->cuda_vec))
152
+ #endif
153
+ cupdlp_free(vec);
154
+ }
155
+
156
+ return 0;
157
+ }
158
+
159
+ void iterates_clear(CUPDLPiterates *iterates) {
160
+ if (iterates) {
161
+ if (iterates->x) {
162
+ // CUPDLP_FREE_VEC(iterates->x);
163
+ vec_clear(iterates->x);
164
+ }
165
+ if (iterates->y) {
166
+ // CUPDLP_FREE_VEC(iterates->y);
167
+ vec_clear(iterates->y);
168
+ }
169
+ if (iterates->xUpdate) {
170
+ // CUPDLP_FREE_VEC(iterates->xUpdate);
171
+ vec_clear(iterates->xUpdate);
172
+ }
173
+ if (iterates->yUpdate) {
174
+ // CUPDLP_FREE_VEC(iterates->yUpdate);
175
+ vec_clear(iterates->yUpdate);
176
+ }
177
+ if (iterates->xSum) {
178
+ CUPDLP_FREE_VEC(iterates->xSum);
179
+ }
180
+ if (iterates->ySum) {
181
+ CUPDLP_FREE_VEC(iterates->ySum);
182
+ }
183
+ if (iterates->xAverage) {
184
+ // CUPDLP_FREE_VEC(iterates->xAverage);
185
+ vec_clear(iterates->xAverage);
186
+ }
187
+ if (iterates->yAverage) {
188
+ // CUPDLP_FREE_VEC(iterates->yAverage);
189
+ vec_clear(iterates->yAverage);
190
+ }
191
+ if (iterates->xLastRestart) {
192
+ CUPDLP_FREE_VEC(iterates->xLastRestart);
193
+ }
194
+ if (iterates->yLastRestart) {
195
+ CUPDLP_FREE_VEC(iterates->yLastRestart);
196
+ }
197
+ if (iterates->ax) {
198
+ // CUPDLP_FREE_VEC(iterates->ax);
199
+ vec_clear(iterates->ax);
200
+ }
201
+ if (iterates->axUpdate) {
202
+ // CUPDLP_FREE_VEC(iterates->axUpdate);
203
+ vec_clear(iterates->axUpdate);
204
+ }
205
+ if (iterates->axAverage) {
206
+ // CUPDLP_FREE_VEC(iterates->axAverage);
207
+ vec_clear(iterates->axAverage);
208
+ }
209
+ if (iterates->aty) {
210
+ // CUPDLP_FREE_VEC(iterates->aty);
211
+ vec_clear(iterates->aty);
212
+ }
213
+ if (iterates->atyUpdate) {
214
+ // CUPDLP_FREE_VEC(iterates->atyUpdate);
215
+ vec_clear(iterates->atyUpdate);
216
+ }
217
+ if (iterates->atyAverage) {
218
+ // CUPDLP_FREE_VEC(iterates->atyAverage);
219
+ vec_clear(iterates->atyAverage);
220
+ }
221
+ CUPDLP_FREE_VEC(iterates);
222
+ }
223
+ }
224
+
225
+ void resobj_clear(CUPDLPresobj *resobj) {
226
+ if (resobj) {
227
+ if (resobj->primalResidual) {
228
+ CUPDLP_FREE_VEC(resobj->primalResidual);
229
+ }
230
+ if (resobj->dualResidual) {
231
+ CUPDLP_FREE_VEC(resobj->dualResidual);
232
+ }
233
+ if (resobj->primalResidualAverage) {
234
+ CUPDLP_FREE_VEC(resobj->primalResidualAverage);
235
+ }
236
+ if (resobj->dualResidualAverage) {
237
+ CUPDLP_FREE_VEC(resobj->dualResidualAverage);
238
+ }
239
+ if (resobj->dSlackPos) {
240
+ CUPDLP_FREE_VEC(resobj->dSlackPos);
241
+ }
242
+ if (resobj->dSlackNeg) {
243
+ CUPDLP_FREE_VEC(resobj->dSlackNeg);
244
+ }
245
+ if (resobj->dSlackPosAverage) {
246
+ CUPDLP_FREE_VEC(resobj->dSlackPosAverage);
247
+ }
248
+ if (resobj->dSlackNegAverage) {
249
+ CUPDLP_FREE_VEC(resobj->dSlackNegAverage);
250
+ }
251
+ if (resobj->dLowerFiltered) {
252
+ CUPDLP_FREE_VEC(resobj->dLowerFiltered);
253
+ }
254
+ if (resobj->dUpperFiltered) {
255
+ CUPDLP_FREE_VEC(resobj->dUpperFiltered);
256
+ }
257
+ if (resobj->primalInfeasRay) {
258
+ CUPDLP_FREE_VEC(resobj->primalInfeasRay);
259
+ }
260
+ if (resobj->primalInfeasConstr) {
261
+ CUPDLP_FREE_VEC(resobj->primalInfeasConstr);
262
+ }
263
+ if (resobj->primalInfeasBound) {
264
+ CUPDLP_FREE_VEC(resobj->primalInfeasBound);
265
+ }
266
+ if (resobj->dualInfeasRay) {
267
+ CUPDLP_FREE_VEC(resobj->dualInfeasRay);
268
+ }
269
+ if (resobj->dualInfeasLbRay) {
270
+ CUPDLP_FREE_VEC(resobj->dualInfeasLbRay);
271
+ }
272
+ if (resobj->dualInfeasUbRay) {
273
+ CUPDLP_FREE_VEC(resobj->dualInfeasUbRay);
274
+ }
275
+ if (resobj->dualInfeasConstr) {
276
+ CUPDLP_FREE_VEC(resobj->dualInfeasConstr);
277
+ }
278
+ // if (resobj->dualInfeasBound) {
279
+ // CUPDLP_FREE_VEC(resobj->dualInfeasBound);
280
+ // }
281
+ CUPDLP_FREE_VEC(resobj);
282
+ }
283
+ }
284
+
285
+ void stepsize_clear(CUPDLPstepsize *stepsize) {
286
+ if (stepsize) {
287
+ cupdlp_free(stepsize);
288
+ }
289
+ }
290
+
291
+ void timers_clear(CUPDLPtimers *timers) {
292
+ #ifndef CUPDLP_CPU
293
+ cupdlp_printf("%20s %e\n", "Free Device memory", timers->FreeDeviceMemTime);
294
+ #endif
295
+
296
+ if (timers) {
297
+ cupdlp_free(timers);
298
+ }
299
+ }
300
+
301
+ void scaling_clear(CUPDLPscaling *scaling) {
302
+ if (scaling) {
303
+ if (scaling->colScale) {
304
+ // cupdlp_free(scaling->colScale);
305
+ CUPDLP_FREE_VEC(scaling->colScale); // now on gpu
306
+ }
307
+ if (scaling->rowScale) {
308
+ // cupdlp_free(scaling->rowScale);
309
+ CUPDLP_FREE_VEC(scaling->rowScale); // now on gpu
310
+ }
311
+ cupdlp_free(scaling);
312
+ }
313
+ }
314
+
315
+ cupdlp_int PDHG_Clear(CUPDLPwork *w) {
316
+ CUPDLPproblem *problem = w->problem;
317
+ CUPDLPsettings *settings = w->settings;
318
+ CUPDLPiterates *iterates = w->iterates;
319
+ CUPDLPresobj *resobj = w->resobj;
320
+ CUPDLPstepsize *stepsize = w->stepsize;
321
+ CUPDLPtimers *timers = w->timers;
322
+ CUPDLPscaling *scaling = w->scaling;
323
+
324
+ if (w) {
325
+ cupdlp_float begin = getTimeStamp();
326
+ #ifndef CUPDLP_CPU
327
+
328
+ // CUDAmv *MV = w->MV;
329
+ // if (MV)
330
+ // {
331
+ // cupdlp_float begin = getTimeStamp();
332
+ // cuda_free_mv(MV);
333
+ // timers->FreeDeviceMemTime += getTimeStamp() - begin;
334
+ // }
335
+ CHECK_CUBLAS(cublasDestroy(w->cublashandle))
336
+ CHECK_CUSPARSE(cusparseDestroy(w->cusparsehandle))
337
+ CHECK_CUDA(cudaFree(w->dBuffer))
338
+ if (w->buffer2) CUPDLP_FREE_VEC(w->buffer2);
339
+ if (w->buffer3) CUPDLP_FREE_VEC(w->buffer3);
340
+ #endif
341
+ if (w->colScale) CUPDLP_FREE_VEC(w->colScale);
342
+ if (w->rowScale) CUPDLP_FREE_VEC(w->rowScale);
343
+
344
+ if (w->buffer) {
345
+ // CUPDLP_FREE_VEC(w->buffer);
346
+ vec_clear(w->buffer);
347
+ }
348
+
349
+ if (problem) {
350
+ // problem_clear(problem);
351
+ problem = cupdlp_NULL;
352
+ }
353
+
354
+ if (iterates) {
355
+ iterates_clear(iterates);
356
+ }
357
+
358
+ if (resobj) {
359
+ resobj_clear(resobj);
360
+ }
361
+
362
+ #ifndef CUPDLP_CPU
363
+ timers->FreeDeviceMemTime += getTimeStamp() - begin;
364
+ #endif
365
+
366
+ if (settings) {
367
+ settings_clear(settings);
368
+ }
369
+ if (stepsize) {
370
+ stepsize_clear(stepsize);
371
+ }
372
+ if (timers) {
373
+ timers_clear(timers);
374
+ }
375
+ if (scaling) {
376
+ // scaling_clear(scaling);
377
+ scaling = cupdlp_NULL;
378
+ }
379
+ cupdlp_free(w);
380
+ }
381
+
382
+ return 0;
383
+ }
384
+
385
+ void PDHG_PrintPDHGParam(CUPDLPwork *w) {
386
+ if (w->settings->nLogLevel < 2) return;
387
+ CUPDLPsettings *settings = w->settings;
388
+ CUPDLPstepsize *stepsize = w->stepsize;
389
+ CUPDLPresobj *resobj = w->resobj;
390
+ CUPDLPiterates *iterates = w->iterates;
391
+ CUPDLPscaling *scaling = w->scaling;
392
+ CUPDLPtimers *timers = w->timers;
393
+
394
+ cupdlp_printf("\n");
395
+
396
+ cupdlp_printf("\n");
397
+ cupdlp_printf("--------------------------------------------------\n");
398
+ cupdlp_printf("CUPDHG Parameters:\n");
399
+ cupdlp_printf("--------------------------------------------------\n");
400
+ cupdlp_printf("\n");
401
+
402
+ cupdlp_printf(" nIterLim: %d\n", settings->nIterLim);
403
+ cupdlp_printf(" dTimeLim (sec): %.2f\n", settings->dTimeLim);
404
+ cupdlp_printf(" ifScaling: %d\n", settings->ifScaling);
405
+ // cupdlp_printf(" iScalingMethod: %d\n", settings->iScalingMethod);)
406
+ cupdlp_printf(" ifRuizScaling: %d\n", scaling->ifRuizScaling);
407
+ cupdlp_printf(" ifL2Scaling: %d\n", scaling->ifL2Scaling);
408
+ cupdlp_printf(" ifPcScaling: %d\n", scaling->ifPcScaling);
409
+ cupdlp_printf(" eLineSearchMethod: %d\n", stepsize->eLineSearchMethod);
410
+ // cupdlp_printf(" dScalingLimit: %.4e\n", settings->dScalingLimit);
411
+ cupdlp_printf(" dPrimalTol: %.4e\n", settings->dPrimalTol);
412
+ cupdlp_printf(" dDualTol: %.4e\n", settings->dDualTol);
413
+ cupdlp_printf(" dGapTol: %.4e\n", settings->dGapTol);
414
+ cupdlp_printf(" dFeasTol: %.4e\n", resobj->dFeasTol);
415
+ cupdlp_printf(" eRestartMethod: %d\n", settings->eRestartMethod);
416
+ cupdlp_printf(" nLogLevel: %d\n", settings->nLogLevel);
417
+ cupdlp_printf(" nLogInterval: %d\n", settings->nLogInterval);
418
+ cupdlp_printf(" iInfNormAbsLocalTermination: %d\n", settings->iInfNormAbsLocalTermination);
419
+ cupdlp_printf("\n");
420
+ cupdlp_printf("--------------------------------------------------\n");
421
+ cupdlp_printf("\n");
422
+ }
423
+
424
+ void PDHG_PrintHugeCUPDHG() {
425
+ cupdlp_printf("\n");
426
+ cupdlp_printf(" ____ _ _ ____ ____ _ ____\n");
427
+ cupdlp_printf(" / ___| | | | _ \\| _ \\| | | _ \\\n");
428
+ cupdlp_printf("| | | | | | |_) | | | | | | |_) |\n");
429
+ cupdlp_printf("| |___| |_| | __/| |_| | |___| __/\n");
430
+ cupdlp_printf(" \\____|\\___/|_| |____/|_____|_|\n");
431
+ cupdlp_printf("\n");
432
+ }
433
+
434
+ void PDHG_PrintUserParamHelper() {
435
+ PDHG_PrintHugeCUPDHG();
436
+
437
+ cupdlp_printf("CUPDHG User Parameters:\n");
438
+ cupdlp_printf("\n");
439
+
440
+ cupdlp_printf(" -h: print this helper\n");
441
+ cupdlp_printf("\n");
442
+
443
+ cupdlp_printf(" -nIterLim: maximum iteration number\n");
444
+ cupdlp_printf(" type: int\n");
445
+ cupdlp_printf(" default: INT_MAX\n");
446
+ cupdlp_printf(" range: >= 0\n");
447
+ cupdlp_printf("\n");
448
+
449
+ cupdlp_printf(" -ifScaling: whether to use scaling\n");
450
+ cupdlp_printf(" type: bool\n");
451
+ cupdlp_printf(" default: true\n");
452
+ cupdlp_printf(" range: true or false\n");
453
+ cupdlp_printf("\n");
454
+
455
+ cupdlp_printf(" -eLineSearchMethod: which line search method to use\n");
456
+ cupdlp_printf(
457
+ " 0-Fixed, 1-Malitsky (not support), "
458
+ "2-Adaptive\n");
459
+ cupdlp_printf(" type: int\n");
460
+ cupdlp_printf(" default: 2\n");
461
+ cupdlp_printf(" range: 0 to 2\n");
462
+ cupdlp_printf("\n");
463
+
464
+ cupdlp_printf(" -dPrimalTol: primal tolerance\n");
465
+ cupdlp_printf(" type: double\n");
466
+ cupdlp_printf(" default: 1e-4\n");
467
+ cupdlp_printf(" range: >= 0\n");
468
+ cupdlp_printf("\n");
469
+
470
+ cupdlp_printf(" -dDualTol: dual tolerance\n");
471
+ cupdlp_printf(" type: double\n");
472
+ cupdlp_printf(" default: 1e-4\n");
473
+ cupdlp_printf(" range: >= 0\n");
474
+ cupdlp_printf("\n");
475
+
476
+ cupdlp_printf(" -dGapTol: gap tolerance\n");
477
+ cupdlp_printf(" type: double\n");
478
+ cupdlp_printf(" default: 1e-4\n");
479
+ cupdlp_printf(" range: >= 0\n");
480
+ cupdlp_printf("\n");
481
+
482
+ cupdlp_printf(" -dFeasTol: feasibility tolerance\n");
483
+ cupdlp_printf(" type: double\n");
484
+ cupdlp_printf(" default: 1e-8\n");
485
+ cupdlp_printf(" range: >= 0\n");
486
+ cupdlp_printf("\n");
487
+
488
+ cupdlp_printf(" -dTimeLim: time limit (in seconds)\n");
489
+ cupdlp_printf(" type: double\n");
490
+ cupdlp_printf(" default: 3600\n");
491
+ cupdlp_printf(" range: >= 0\n");
492
+ cupdlp_printf("\n");
493
+
494
+ cupdlp_printf(" -eRestartMethod: which restart method to use\n");
495
+ cupdlp_printf(" 0-None, 1-KKTversion\n");
496
+ cupdlp_printf(" type: int\n");
497
+ cupdlp_printf(" default: 1\n");
498
+ cupdlp_printf(" range: 0 to 1\n");
499
+ cupdlp_printf("\n");
500
+
501
+ cupdlp_printf(" -ifRuizScaling: whether to use Ruiz scaling\n");
502
+ cupdlp_printf(" type: bool\n");
503
+ cupdlp_printf(" default: true\n");
504
+ cupdlp_printf(" range: true or false\n");
505
+ cupdlp_printf("\n");
506
+
507
+ cupdlp_printf(" -ifL2Scaling: whether to use L2 scaling\n");
508
+ cupdlp_printf(" type: bool\n");
509
+ cupdlp_printf(" default: false\n");
510
+ cupdlp_printf(" range: true or false\n");
511
+ cupdlp_printf("\n");
512
+
513
+ cupdlp_printf(" -ifPcScaling: whether to use Pock-Chambolle scaling\n");
514
+ cupdlp_printf(" type: bool\n");
515
+ cupdlp_printf(" default: true\n");
516
+ cupdlp_printf(" range: true or false\n");
517
+ cupdlp_printf("\n");
518
+
519
+ // cupdlp_printf(
520
+ // " -ifPre: whether to use HiGHS presolver (and thus postsolver)\n");
521
+ // cupdlp_printf(" type: bool\n");
522
+ // cupdlp_printf(" default: true\n");
523
+ // cupdlp_printf(" range: true or false\n");
524
+ // cupdlp_printf("\n");
525
+ }
526
+
527
+ cupdlp_retcode getUserParam(int argc, char **argv,
528
+ cupdlp_bool *ifChangeIntParam, cupdlp_int *intParam,
529
+ cupdlp_bool *ifChangeFloatParam,
530
+ cupdlp_float *floatParam) {
531
+ cupdlp_retcode retcode = RETCODE_OK;
532
+
533
+ // set ifChangeIntParam and ifChangeFloatParam to false
534
+ for (cupdlp_int i = 0; i < N_INT_USER_PARAM; ++i) {
535
+ ifChangeIntParam[i] = false;
536
+ }
537
+
538
+ for (cupdlp_int i = 0; i < N_FLOAT_USER_PARAM; ++i) {
539
+ ifChangeFloatParam[i] = false;
540
+ }
541
+
542
+ // parse command line arguments
543
+ for (cupdlp_int i = 0; i < argc - 1; ++i) {
544
+ if (strcmp(argv[i], "-h") == 0) {
545
+ PDHG_PrintUserParamHelper();
546
+
547
+ retcode = RETCODE_FAILED;
548
+ goto exit_cleanup;
549
+ }
550
+
551
+ if (strcmp(argv[i], "-nIterLim") == 0) {
552
+ ifChangeIntParam[N_ITER_LIM] = true;
553
+ intParam[N_ITER_LIM] = atoi(argv[i + 1]);
554
+ } else if (strcmp(argv[i], "-ifScaling") == 0) {
555
+ ifChangeIntParam[IF_SCALING] = true;
556
+ intParam[IF_SCALING] = atoi(argv[i + 1]);
557
+ } else if (strcmp(argv[i], "-iScalingMethod") == 0) {
558
+ ifChangeIntParam[I_SCALING_METHOD] = true;
559
+ intParam[I_SCALING_METHOD] = atoi(argv[i + 1]);
560
+ } else if (strcmp(argv[i], "-eLineSearchMethod") == 0) {
561
+ ifChangeIntParam[E_LINE_SEARCH_METHOD] = true;
562
+ intParam[E_LINE_SEARCH_METHOD] = atoi(argv[i + 1]);
563
+ } else if (strcmp(argv[i], "-dScalingLimit") == 0) {
564
+ ifChangeFloatParam[D_SCALING_LIMIT] = true;
565
+ floatParam[D_SCALING_LIMIT] = atof(argv[i + 1]);
566
+ } else if (strcmp(argv[i], "-dPrimalTol") == 0) {
567
+ ifChangeFloatParam[D_PRIMAL_TOL] = true;
568
+ floatParam[D_PRIMAL_TOL] = atof(argv[i + 1]);
569
+ } else if (strcmp(argv[i], "-dDualTol") == 0) {
570
+ ifChangeFloatParam[D_DUAL_TOL] = true;
571
+ floatParam[D_DUAL_TOL] = atof(argv[i + 1]);
572
+ } else if (strcmp(argv[i], "-dGapTol") == 0) {
573
+ ifChangeFloatParam[D_GAP_TOL] = true;
574
+ floatParam[D_GAP_TOL] = atof(argv[i + 1]);
575
+ } else if (strcmp(argv[i], "-dFeasTol") == 0) {
576
+ ifChangeFloatParam[D_FEAS_TOL] = true;
577
+ floatParam[D_FEAS_TOL] = atof(argv[i + 1]);
578
+ } else if (strcmp(argv[i], "-dTimeLim") == 0) {
579
+ ifChangeFloatParam[D_TIME_LIM] = true;
580
+ floatParam[D_TIME_LIM] = atof(argv[i + 1]);
581
+ } else if (strcmp(argv[i], "-eRestartMethod") == 0) {
582
+ ifChangeIntParam[E_RESTART_METHOD] = true;
583
+ intParam[E_RESTART_METHOD] = atoi(argv[i + 1]);
584
+ } else if (strcmp(argv[i], "-ifRuizScaling") == 0) {
585
+ ifChangeIntParam[IF_RUIZ_SCALING] = true;
586
+ intParam[IF_RUIZ_SCALING] = atoi(argv[i + 1]);
587
+ } else if (strcmp(argv[i], "-ifL2Scaling") == 0) {
588
+ ifChangeIntParam[IF_L2_SCALING] = true;
589
+ intParam[IF_L2_SCALING] = atoi(argv[i + 1]);
590
+ } else if (strcmp(argv[i], "-ifPcScaling") == 0) {
591
+ ifChangeIntParam[IF_PC_SCALING] = true;
592
+ intParam[IF_PC_SCALING] = atoi(argv[i + 1]);
593
+ } else if (strcmp(argv[i], "-nLogLevel") == 0) {
594
+ ifChangeIntParam[N_LOG_LEVEL] = true;
595
+ intParam[N_LOG_LEVEL] = atoi(argv[i + 1]);
596
+ } else if (strcmp(argv[i], "-nLogInt") == 0) {
597
+ ifChangeIntParam[N_LOG_INTERVAL] = true;
598
+ intParam[N_LOG_INTERVAL] = atoi(argv[i + 1]);
599
+ } else if (strcmp(argv[i], "-ifPre") == 0) {
600
+ ifChangeIntParam[IF_PRESOLVE] = true;
601
+ intParam[IF_PRESOLVE] = atoi(argv[i + 1]);
602
+ }
603
+ }
604
+
605
+ if (argc>0) {
606
+ if (strcmp(argv[argc - 1], "-h") == 0) {
607
+ PDHG_PrintUserParamHelper();
608
+
609
+ retcode = RETCODE_FAILED;
610
+ goto exit_cleanup;
611
+ }
612
+ }
613
+
614
+ exit_cleanup:
615
+ return retcode;
616
+ }
617
+
618
+ cupdlp_retcode settings_SetUserParam(CUPDLPsettings *settings,
619
+ cupdlp_bool *ifChangeIntParam,
620
+ cupdlp_int *intParam,
621
+ cupdlp_bool *ifChangeFloatParam,
622
+ cupdlp_float *floatParam) {
623
+ cupdlp_retcode retcode = RETCODE_OK;
624
+
625
+ if (ifChangeIntParam[N_ITER_LIM]) {
626
+ settings->nIterLim = intParam[N_ITER_LIM];
627
+ }
628
+
629
+ if (ifChangeIntParam[N_LOG_LEVEL]) {
630
+ settings->nLogLevel = intParam[N_LOG_LEVEL];
631
+ }
632
+
633
+ if (ifChangeIntParam[N_LOG_INTERVAL]) {
634
+ settings->nLogInterval = intParam[N_LOG_INTERVAL];
635
+ }
636
+
637
+ if (ifChangeIntParam[IF_SCALING]) {
638
+ settings->ifScaling = intParam[IF_SCALING];
639
+ }
640
+
641
+ if (ifChangeIntParam[I_SCALING_METHOD]) {
642
+ settings->iScalingMethod = intParam[I_SCALING_METHOD];
643
+ }
644
+
645
+ if (ifChangeFloatParam[D_SCALING_LIMIT]) {
646
+ settings->dScalingLimit = floatParam[D_SCALING_LIMIT];
647
+ }
648
+
649
+ if (ifChangeFloatParam[D_PRIMAL_TOL]) {
650
+ settings->dPrimalTol = floatParam[D_PRIMAL_TOL];
651
+ }
652
+
653
+ if (ifChangeFloatParam[D_DUAL_TOL]) {
654
+ settings->dDualTol = floatParam[D_DUAL_TOL];
655
+ }
656
+
657
+ if (ifChangeFloatParam[D_GAP_TOL]) {
658
+ settings->dGapTol = floatParam[D_GAP_TOL];
659
+ }
660
+
661
+ if (ifChangeFloatParam[D_TIME_LIM]) {
662
+ settings->dTimeLim = floatParam[D_TIME_LIM];
663
+ }
664
+
665
+ if (ifChangeIntParam[E_RESTART_METHOD]) {
666
+ settings->eRestartMethod = intParam[E_RESTART_METHOD];
667
+ }
668
+
669
+ if (ifChangeIntParam[I_INF_NORM_ABS_LOCAL_TERMINATION]) {
670
+ settings->iInfNormAbsLocalTermination = intParam[I_INF_NORM_ABS_LOCAL_TERMINATION];
671
+ }
672
+
673
+ exit_cleanup:
674
+ return retcode;
675
+ }
676
+
677
+ cupdlp_retcode resobj_SetUserParam(CUPDLPresobj *resobj,
678
+ cupdlp_bool *ifChangeIntParam,
679
+ cupdlp_int *intParam,
680
+ cupdlp_bool *ifChangeFloatParam,
681
+ cupdlp_float *floatParam) {
682
+ cupdlp_retcode retcode = RETCODE_OK;
683
+
684
+ if (ifChangeFloatParam[D_FEAS_TOL]) {
685
+ resobj->dFeasTol = floatParam[D_FEAS_TOL];
686
+ }
687
+
688
+ exit_cleanup:
689
+ return retcode;
690
+ }
691
+
692
+ cupdlp_retcode iterates_SetUserParam(CUPDLPiterates *iterates,
693
+ cupdlp_bool *ifChangeIntParam,
694
+ cupdlp_int *intParam,
695
+ cupdlp_bool *ifChangeFloatParam,
696
+ cupdlp_float *floatParam) {
697
+ cupdlp_retcode retcode = RETCODE_OK;
698
+
699
+ exit_cleanup:
700
+ return retcode;
701
+ }
702
+
703
+ cupdlp_retcode stepsize_SetUserParam(CUPDLPstepsize *stepsize,
704
+ cupdlp_bool *ifChangeIntParam,
705
+ cupdlp_int *intParam,
706
+ cupdlp_bool *ifChangeFloatParam,
707
+ cupdlp_float *floatParam) {
708
+ cupdlp_retcode retcode = RETCODE_OK;
709
+
710
+ if (ifChangeIntParam[E_LINE_SEARCH_METHOD]) {
711
+ stepsize->eLineSearchMethod = intParam[E_LINE_SEARCH_METHOD];
712
+ }
713
+
714
+ exit_cleanup:
715
+ return retcode;
716
+ }
717
+
718
+ cupdlp_retcode scaling_SetUserParam(CUPDLPscaling *scaling,
719
+ cupdlp_bool *ifChangeIntParam,
720
+ cupdlp_int *intParam,
721
+ cupdlp_bool *ifChangeFloatParam,
722
+ cupdlp_float *floatParam) {
723
+ cupdlp_retcode retcode = RETCODE_OK;
724
+
725
+ if (ifChangeIntParam[IF_RUIZ_SCALING]) {
726
+ scaling->ifRuizScaling = intParam[IF_RUIZ_SCALING];
727
+ }
728
+
729
+ if (ifChangeIntParam[IF_L2_SCALING]) {
730
+ scaling->ifL2Scaling = intParam[IF_L2_SCALING];
731
+ }
732
+
733
+ if (ifChangeIntParam[IF_PC_SCALING]) {
734
+ scaling->ifPcScaling = intParam[IF_PC_SCALING];
735
+ }
736
+
737
+ exit_cleanup:
738
+ return retcode;
739
+ }
740
+
741
+ cupdlp_retcode timers_SetUserParam(CUPDLPtimers *timers,
742
+ cupdlp_bool *ifChangeIntParam,
743
+ cupdlp_int *intParam,
744
+ cupdlp_bool *ifChangeFloatParam,
745
+ cupdlp_float *floatParam) {
746
+ cupdlp_retcode retcode = RETCODE_OK;
747
+
748
+ exit_cleanup:
749
+ return retcode;
750
+ }
751
+
752
+ cupdlp_retcode PDHG_SetUserParam(CUPDLPwork *w, cupdlp_bool *ifChangeIntParam,
753
+ cupdlp_int *intParam,
754
+ cupdlp_bool *ifChangeFloatParam,
755
+ cupdlp_float *floatParam) {
756
+ cupdlp_retcode retcode = RETCODE_OK;
757
+
758
+ CUPDLPsettings *settings = w->settings;
759
+ CUPDLPstepsize *stepsize = w->stepsize;
760
+ CUPDLPresobj *resobj = w->resobj;
761
+ CUPDLPiterates *iterates = w->iterates;
762
+ CUPDLPscaling *scaling = w->scaling;
763
+ CUPDLPtimers *timers = w->timers;
764
+
765
+ CUPDLP_CALL(settings_SetUserParam(settings, ifChangeIntParam, intParam,
766
+ ifChangeFloatParam, floatParam));
767
+ CUPDLP_CALL(stepsize_SetUserParam(stepsize, ifChangeIntParam, intParam,
768
+ ifChangeFloatParam, floatParam));
769
+ CUPDLP_CALL(resobj_SetUserParam(resobj, ifChangeIntParam, intParam,
770
+ ifChangeFloatParam, floatParam));
771
+ CUPDLP_CALL(iterates_SetUserParam(iterates, ifChangeIntParam, intParam,
772
+ ifChangeFloatParam, floatParam));
773
+ CUPDLP_CALL(scaling_SetUserParam(scaling, ifChangeIntParam, intParam,
774
+ ifChangeFloatParam, floatParam));
775
+ CUPDLP_CALL(timers_SetUserParam(timers, ifChangeIntParam, intParam,
776
+ ifChangeFloatParam, floatParam));
777
+
778
+ PDHG_PrintPDHGParam(w);
779
+
780
+ exit_cleanup:
781
+ return retcode;
782
+ }
783
+
784
+ cupdlp_retcode settings_Alloc(CUPDLPsettings *settings) {
785
+ cupdlp_retcode retcode = RETCODE_OK;
786
+ // settings->nIterLim = INFINITY;
787
+ settings->nIterLim = INT_MAX; // INFINITY cause bug on MacOS
788
+ settings->nLogLevel = 2; // Ensures that, by default, cuPDLP-C printing is unchanged
789
+ settings->nLogInterval = 100;
790
+ // settings->dTimeLim = INFINITY;
791
+ settings->dTimeLim = 3600;
792
+ settings->ifScaling = true;
793
+ settings->iScalingMethod = 3; // no use
794
+ settings->dScalingLimit = 5; // no use
795
+ settings->eRestartMethod = PDHG_GPU_RESTART;
796
+ settings->iInfNormAbsLocalTermination = 0;
797
+
798
+ // termination criteria
799
+ settings->dPrimalTol = 1e-4;
800
+ settings->dDualTol = 1e-4;
801
+ settings->dGapTol = 1e-4;
802
+
803
+ return retcode;
804
+ }
805
+
806
+ cupdlp_retcode resobj_Alloc(CUPDLPresobj *resobj, CUPDLPproblem *problem,
807
+ cupdlp_int ncols, cupdlp_int nrows) {
808
+ cupdlp_retcode retcode = RETCODE_OK;
809
+
810
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->primalResidual, nrows);
811
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dualResidual, ncols);
812
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->primalResidualAverage, nrows);
813
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dualResidualAverage, ncols);
814
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dSlackPos, ncols);
815
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dSlackNeg, ncols);
816
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dSlackPosAverage, ncols);
817
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dSlackNegAverage, ncols);
818
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dLowerFiltered, ncols);
819
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dUpperFiltered, ncols);
820
+
821
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->primalInfeasRay, ncols);
822
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->primalInfeasConstr, nrows);
823
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->primalInfeasBound, ncols);
824
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dualInfeasRay, nrows);
825
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dualInfeasLbRay, ncols);
826
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dualInfeasUbRay, ncols);
827
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(resobj->dualInfeasConstr, ncols);
828
+ // CUPDLP_INIT_DOUBLE_ZERO_VEC(resobj->dualInfeasBound, nrows);
829
+
830
+ // need to translate to cuda type
831
+ // for (int i = 0; i < ncols; i++)
832
+ // {
833
+ // resobj->dLowerFiltered[i] = problem->lower[i] > -INFINITY ?
834
+ // problem->lower[i] : 0.0; resobj->dUpperFiltered[i] = problem->upper[i]
835
+ // < +INFINITY ? problem->upper[i] : 0.0;
836
+ // }
837
+
838
+ cupdlp_filterlb(resobj->dLowerFiltered, problem->lower, -INFINITY, ncols);
839
+ cupdlp_filterub(resobj->dUpperFiltered, problem->upper, +INFINITY, ncols);
840
+
841
+ // initialization
842
+ resobj->dFeasTol = 1e-8;
843
+ resobj->dPrimalObj = 0.0;
844
+ resobj->dDualObj = 0.0;
845
+ resobj->dDualityGap = 0.0;
846
+ resobj->dComplementarity = 0.0;
847
+ resobj->dPrimalFeas = 0.0;
848
+ resobj->dDualFeas = 0.0;
849
+ resobj->dRelObjGap = 0.0;
850
+ resobj->dPrimalObjAverage = 0.0;
851
+ resobj->dDualObjAverage = 0.0;
852
+ resobj->dDualityGapAverage = 0.0;
853
+ resobj->dComplementarityAverage = 0.0;
854
+ resobj->dPrimalFeasAverage = 0.0;
855
+ resobj->dDualFeasAverage = 0.0;
856
+ resobj->dRelObjGapAverage = 0.0;
857
+ resobj->dPrimalFeasLastRestart = 0.0;
858
+ resobj->dDualFeasLastRestart = 0.0;
859
+ resobj->dDualityGapLastRestart = 0.0;
860
+ resobj->dPrimalFeasLastCandidate = 0.0;
861
+ resobj->dDualFeasLastCandidate = 0.0;
862
+ resobj->dDualityGapLastCandidate = 0.0;
863
+
864
+ resobj->primalCode = FEASIBLE;
865
+ resobj->dualCode = FEASIBLE;
866
+ resobj->termInfeasIterate = LAST_ITERATE;
867
+ resobj->dPrimalInfeasObj = 0.0;
868
+ resobj->dDualInfeasObj = 0.0;
869
+ resobj->dPrimalInfeasRes = 1.0;
870
+ resobj->dDualInfeasRes = 1.0;
871
+ resobj->dPrimalInfeasObjAverage = 0.0;
872
+ resobj->dDualInfeasObjAverage = 0.0;
873
+ resobj->dPrimalInfeasResAverage = 1.0;
874
+ resobj->dDualInfeasResAverage = 1.0;
875
+
876
+ resobj->termCode = TIMELIMIT_OR_ITERLIMIT;
877
+ resobj->termIterate = LAST_ITERATE;
878
+
879
+ // todo, pass work
880
+ // cupdlp_twoNorm(problem->cost, ncols, &resobj->dNormCost);
881
+ // twoNorm(problem->rhs, nrows);
882
+
883
+ exit_cleanup:
884
+ return retcode;
885
+ }
886
+
887
+ cupdlp_retcode iterates_Alloc(CUPDLPiterates *iterates, cupdlp_int ncols,
888
+ cupdlp_int nrows) {
889
+ cupdlp_retcode retcode = RETCODE_OK;
890
+
891
+ iterates->nCols = ncols;
892
+ iterates->nRows = nrows;
893
+
894
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(iterates->xSum, ncols);
895
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(iterates->ySum, nrows);
896
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(iterates->xLastRestart, ncols);
897
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(iterates->yLastRestart, nrows);
898
+
899
+ CUPDLP_INIT_CUPDLP_VEC(iterates->x, 1);
900
+ CUPDLP_INIT_CUPDLP_VEC(iterates->xUpdate, 1);
901
+ CUPDLP_INIT_CUPDLP_VEC(iterates->xAverage, 1);
902
+ CUPDLP_INIT_CUPDLP_VEC(iterates->y, 1);
903
+ CUPDLP_INIT_CUPDLP_VEC(iterates->yUpdate, 1);
904
+ CUPDLP_INIT_CUPDLP_VEC(iterates->yAverage, 1);
905
+ CUPDLP_INIT_CUPDLP_VEC(iterates->ax, 1);
906
+ CUPDLP_INIT_CUPDLP_VEC(iterates->axUpdate, 1);
907
+ CUPDLP_INIT_CUPDLP_VEC(iterates->axAverage, 1);
908
+ CUPDLP_INIT_CUPDLP_VEC(iterates->aty, 1);
909
+ CUPDLP_INIT_CUPDLP_VEC(iterates->atyUpdate, 1);
910
+ CUPDLP_INIT_CUPDLP_VEC(iterates->atyAverage, 1);
911
+
912
+ CUPDLP_CALL(vec_Alloc(iterates->x, ncols));
913
+ CUPDLP_CALL(vec_Alloc(iterates->xUpdate, ncols));
914
+ CUPDLP_CALL(vec_Alloc(iterates->xAverage, ncols));
915
+ CUPDLP_CALL(vec_Alloc(iterates->y, nrows));
916
+ CUPDLP_CALL(vec_Alloc(iterates->yUpdate, nrows));
917
+ CUPDLP_CALL(vec_Alloc(iterates->yAverage, nrows));
918
+ CUPDLP_CALL(vec_Alloc(iterates->ax, nrows));
919
+ CUPDLP_CALL(vec_Alloc(iterates->axUpdate, nrows));
920
+ CUPDLP_CALL(vec_Alloc(iterates->axAverage, nrows));
921
+ CUPDLP_CALL(vec_Alloc(iterates->aty, ncols));
922
+ CUPDLP_CALL(vec_Alloc(iterates->atyUpdate, ncols));
923
+ CUPDLP_CALL(vec_Alloc(iterates->atyAverage, ncols));
924
+
925
+ // initialization
926
+ iterates->iLastRestartIter = 0;
927
+ iterates->dLastRestartDualityGap = 0.0;
928
+ iterates->dLastRestartBeta = 0.0;
929
+
930
+ exit_cleanup:
931
+ return retcode;
932
+ }
933
+
934
+ cupdlp_retcode stepsize_Alloc(CUPDLPstepsize *stepsize) {
935
+ cupdlp_retcode retcode = RETCODE_OK;
936
+
937
+ stepsize->eLineSearchMethod = PDHG_ADAPTIVE_LINESEARCH;
938
+
939
+ // initialization
940
+ stepsize->nStepSizeIter = 0;
941
+ stepsize->dPrimalStep = 0.0;
942
+ stepsize->dDualStep = 0.0;
943
+ stepsize->dSumPrimalStep = 0.0;
944
+ stepsize->dSumDualStep = 0.0;
945
+ stepsize->dBeta = 0.0;
946
+ stepsize->dTheta = 0.0;
947
+
948
+ exit_cleanup:
949
+ return retcode;
950
+ }
951
+
952
+ cupdlp_retcode scaling_Alloc(CUPDLPscaling *scaling, CUPDLPproblem *problem,
953
+ cupdlp_int ncols, cupdlp_int nrows) {
954
+ cupdlp_retcode retcode = RETCODE_OK;
955
+ scaling->ifScaled = 0;
956
+
957
+ CUPDLP_INIT_DOUBLE(scaling->colScale, ncols);
958
+ CUPDLP_INIT_DOUBLE(scaling->rowScale, nrows);
959
+
960
+ scaling->ifRuizScaling = 1;
961
+ scaling->ifL2Scaling = 0;
962
+ scaling->ifPcScaling = 1;
963
+
964
+ scaling->dNormCost = twoNorm(problem->cost, problem->nCols);
965
+ scaling->dNormRhs = twoNorm(problem->rhs, problem->nRows);
966
+
967
+ exit_cleanup:
968
+ return retcode;
969
+ }
970
+
971
+ cupdlp_retcode timers_Alloc(CUPDLPtimers *timers) {
972
+ cupdlp_retcode retcode = RETCODE_OK;
973
+
974
+ timers->nIter = 0;
975
+ timers->dSolvingTime = 0.0;
976
+ timers->dSolvingBeg = 0.0;
977
+ timers->dScalingTime = 0.0;
978
+ timers->dPresolveTime = 0.0;
979
+
980
+ #if PDHG_USE_TIMERS
981
+ timers->dAtyTime = 0.0;
982
+ timers->dAxTime = 0.0;
983
+ timers->dComputeResidualsTime = 0.0;
984
+ timers->dUpdateIterateTime = 0.0;
985
+ timers->nAtyCalls = 0;
986
+ timers->nAxCalls = 0;
987
+ timers->nComputeResidualsCalls = 0;
988
+ timers->nUpdateIterateCalls = 0;
989
+ #endif
990
+ #ifndef CUPDLP_CPU
991
+ // GPU timers
992
+ timers->AllocMem_CopyMatToDeviceTime = 0.0;
993
+ timers->CopyVecToDeviceTime = 0.0;
994
+ timers->DeviceMatVecProdTime = 0.0;
995
+ timers->CopyVecToHostTime = 0.0;
996
+ timers->FreeDeviceMemTime = 0.0;
997
+ timers->CudaPrepareTime = 0.0;
998
+ #endif
999
+
1000
+ exit_cleanup:
1001
+ return retcode;
1002
+ }
1003
+
1004
+ cupdlp_retcode vec_Alloc(CUPDLPvec *vec, cupdlp_int n) {
1005
+ cupdlp_retcode retcode = RETCODE_OK;
1006
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(vec->data, n);
1007
+ vec->len = n;
1008
+ #ifndef CUPDLP_CPU
1009
+ CHECK_CUSPARSE(
1010
+ cusparseCreateDnVec(&vec->cuda_vec, n, vec->data, CudaComputeType));
1011
+ #endif
1012
+
1013
+ exit_cleanup:
1014
+ return retcode;
1015
+ }
1016
+
1017
+ cupdlp_retcode PDHG_Alloc(CUPDLPwork *w) {
1018
+ cupdlp_retcode retcode = RETCODE_OK;
1019
+
1020
+ CUPDLP_INIT_SETTINGS(w->settings, 1);
1021
+ CUPDLP_INIT_RESOBJ(w->resobj, 1);
1022
+ CUPDLP_INIT_ITERATES(w->iterates, 1);
1023
+ CUPDLP_INIT_STEPSIZE(w->stepsize, 1);
1024
+
1025
+ CUPDLP_INIT_TIMERS(w->timers, 1);
1026
+ CUPDLP_CALL(timers_Alloc(w->timers));
1027
+
1028
+ cupdlp_float begin = getTimeStamp();
1029
+ // buffer
1030
+ CUPDLP_INIT_CUPDLP_VEC(w->buffer, 1);
1031
+ CUPDLP_CALL(vec_Alloc(w->buffer, w->problem->data->nRows));
1032
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(w->buffer2,
1033
+ MAX(w->problem->data->nCols, w->problem->data->nRows));
1034
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(w->buffer3,
1035
+ MAX(w->problem->data->nCols, w->problem->data->nRows));
1036
+
1037
+ // for scaling
1038
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(w->colScale, w->problem->data->nCols);
1039
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(w->rowScale, w->problem->data->nRows);
1040
+
1041
+ CUPDLP_CALL(settings_Alloc(w->settings));
1042
+ CUPDLP_CALL(resobj_Alloc(w->resobj, w->problem, w->problem->data->nCols,
1043
+ w->problem->data->nRows));
1044
+ CUPDLP_CALL(iterates_Alloc(w->iterates, w->problem->data->nCols,
1045
+ w->problem->data->nRows));
1046
+ CUPDLP_CALL(stepsize_Alloc(w->stepsize));
1047
+
1048
+ #ifndef CUPDLP_CPU
1049
+ // CHECK_CUSPARSE(cusparseCreate(&w->cusparsehandle));
1050
+ // CHECK_CUBLAS(cublasCreate(&w->cublashandle));
1051
+ cuda_alloc_MVbuffer(
1052
+ // w->problem->data->matrix_format,
1053
+ w->cusparsehandle, w->problem->data->csc_matrix->cuda_csc,
1054
+ w->iterates->x->cuda_vec, w->iterates->ax->cuda_vec,
1055
+ w->problem->data->csr_matrix->cuda_csr, w->iterates->y->cuda_vec,
1056
+ w->iterates->aty->cuda_vec, &w->dBuffer);
1057
+ w->timers->AllocMem_CopyMatToDeviceTime += getTimeStamp() - begin;
1058
+ #endif
1059
+
1060
+ exit_cleanup:
1061
+ return retcode;
1062
+ }
1063
+
1064
+ cupdlp_retcode PDHG_Create(CUPDLPwork **ww, CUPDLPproblem *lp,
1065
+ CUPDLPscaling *scaling) {
1066
+ cupdlp_retcode retcode = RETCODE_OK;
1067
+ CUPDLP_INIT_ZERO_CUPDLP_WORK(*ww, 1);
1068
+
1069
+ CUPDLPwork *w = *ww;
1070
+ w->problem = lp;
1071
+ w->scaling = scaling;
1072
+
1073
+ exit_cleanup:
1074
+ return retcode;
1075
+ }
1076
+
1077
+ void PDHG_Destroy(CUPDLPwork **w) {
1078
+ if (w && *w) {
1079
+ PDHG_Clear(*w);
1080
+ #ifndef CUPDLP_CPU
1081
+ cudaDeviceReset();
1082
+ #endif
1083
+ }
1084
+ }
1085
+
1086
+ void PDHG_Init_Data(CUPDLPwork *work) {}
1087
+
1088
+ double my_clock(void) {
1089
+ #ifdef CUPDLP_TIMER
1090
+ // struct timeval t;
1091
+ // clock_gettime(&t, NULL);
1092
+ // gettimeofday(&t, NULL);
1093
+ double timeee = 0;
1094
+
1095
+ #ifndef WIN32
1096
+ timeee = time(NULL);
1097
+ #else
1098
+ timeee = clock();
1099
+ #endif
1100
+
1101
+ return timeee;
1102
+ // return (1e-06 * t.tv_usec + t.tv_sec);
1103
+ #else
1104
+ return 0;
1105
+ #endif
1106
+ }
1107
+
1108
+ double getTimeStamp(void) { return my_clock(); }
1109
+
1110
+ void dense_copy(CUPDLPdense *dst, CUPDLPdense *src) {
1111
+ dst->nRows = src->nRows;
1112
+ dst->nCols = src->nCols;
1113
+ cupdlp_copy(dst->data, src->data, cupdlp_float, src->nRows * src->nCols);
1114
+
1115
+ return;
1116
+ }
1117
+
1118
+ void csr_copy(CUPDLPcsr *dst, CUPDLPcsr *src) {
1119
+ dst->nRows = src->nRows;
1120
+ dst->nCols = src->nCols;
1121
+ dst->nMatElem = src->nMatElem;
1122
+ cupdlp_copy(dst->rowMatBeg, src->rowMatBeg, cupdlp_int, src->nRows + 1);
1123
+ cupdlp_copy(dst->rowMatIdx, src->rowMatIdx, cupdlp_int, src->nMatElem);
1124
+ cupdlp_copy(dst->rowMatElem, src->rowMatElem, cupdlp_float, src->nMatElem);
1125
+
1126
+ return;
1127
+ }
1128
+
1129
+ cupdlp_int csc_copy(CUPDLPcsc *dst, CUPDLPcsc *src) {
1130
+ dst->nRows = src->nRows;
1131
+ dst->nCols = src->nCols;
1132
+ dst->nMatElem = src->nMatElem;
1133
+ CUPDLP_COPY_VEC(dst->colMatBeg, src->colMatBeg, cupdlp_int, src->nCols + 1);
1134
+ CUPDLP_COPY_VEC(dst->colMatIdx, src->colMatIdx, cupdlp_int, src->nMatElem);
1135
+ CUPDLP_COPY_VEC(dst->colMatElem, src->colMatElem, cupdlp_float,
1136
+ src->nMatElem);
1137
+
1138
+ #ifndef CUPDLP_CPU
1139
+ // Pointer to GPU csc matrix
1140
+ CHECK_CUSPARSE(cusparseCreateCsc(
1141
+ &dst->cuda_csc, src->nRows, src->nCols, src->nMatElem, dst->colMatBeg,
1142
+ dst->colMatIdx, dst->colMatElem, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_32I,
1143
+ CUSPARSE_INDEX_BASE_ZERO, CudaComputeType));
1144
+ #endif
1145
+
1146
+ return 0;
1147
+ }
1148
+
1149
+ void csr2csc(CUPDLPcsc *csc, CUPDLPcsr *csr) {
1150
+ cupdlp_dcs *cs_csr =
1151
+ cupdlp_dcs_spalloc(csr->nCols, csc->nRows, csc->nMatElem, 1, 0);
1152
+ cupdlp_copy(cs_csr->p, csr->rowMatBeg, cupdlp_int, csr->nRows + 1);
1153
+ cupdlp_copy(cs_csr->i, csr->rowMatIdx, cupdlp_int, csr->nMatElem);
1154
+ cupdlp_copy(cs_csr->x, csr->rowMatElem, cupdlp_float, csr->nMatElem);
1155
+
1156
+ cupdlp_dcs *cs_csc = cupdlp_dcs_transpose(cs_csr, 1);
1157
+ csc->nCols = cs_csc->m;
1158
+ csc->nRows = cs_csc->n;
1159
+ csc->nMatElem = cs_csc->nzmax;
1160
+ cupdlp_copy(csc->colMatBeg, cs_csc->p, cupdlp_int, cs_csc->n + 1);
1161
+ cupdlp_copy(csc->colMatIdx, cs_csc->i, cupdlp_int, cs_csc->nzmax);
1162
+ cupdlp_copy(csc->colMatElem, cs_csc->x, cupdlp_float, cs_csc->nzmax);
1163
+
1164
+ // cupdlp_dcs_free(cs_csc);
1165
+ // cupdlp_dcs_free(cs_csr);
1166
+ cupdlp_dcs_spfree(cs_csc);
1167
+ cupdlp_dcs_spfree(cs_csr);
1168
+
1169
+ return;
1170
+ }
1171
+
1172
+ cupdlp_int csc2csr(CUPDLPcsr *csr, CUPDLPcsc *csc) {
1173
+ // The transpose may need to be done on the GPU
1174
+ // Currently, it is done on the CPU
1175
+
1176
+ cupdlp_dcs *cs_csc =
1177
+ cupdlp_dcs_spalloc(csc->nRows, csc->nCols, csc->nMatElem, 1, 0);
1178
+ cupdlp_copy(cs_csc->p, csc->colMatBeg, cupdlp_int, csc->nCols + 1);
1179
+ cupdlp_copy(cs_csc->i, csc->colMatIdx, cupdlp_int, csc->nMatElem);
1180
+ cupdlp_copy(cs_csc->x, csc->colMatElem, cupdlp_float, csc->nMatElem);
1181
+
1182
+ cupdlp_dcs *cs_csr = cupdlp_dcs_transpose(cs_csc, 1);
1183
+ csr->nCols = cs_csr->m;
1184
+ csr->nRows = cs_csr->n;
1185
+ csr->nMatElem = cs_csr->nzmax;
1186
+ CUPDLP_COPY_VEC(csr->rowMatBeg, cs_csr->p, cupdlp_int, cs_csr->n + 1);
1187
+ CUPDLP_COPY_VEC(csr->rowMatIdx, cs_csr->i, cupdlp_int, cs_csr->nzmax);
1188
+ CUPDLP_COPY_VEC(csr->rowMatElem, cs_csr->x, cupdlp_float, cs_csr->nzmax);
1189
+
1190
+ // cupdlp_dcs_free(cs_csc);
1191
+ // cupdlp_dcs_free(cs_csr);
1192
+ cupdlp_dcs_spfree(cs_csc);
1193
+ cupdlp_dcs_spfree(cs_csr);
1194
+
1195
+ #ifndef CUPDLP_CPU
1196
+ // Pointer to GPU csc matrix
1197
+ CHECK_CUSPARSE(cusparseCreateCsr(
1198
+ &csr->cuda_csr, csr->nRows, csr->nCols, csr->nMatElem, csr->rowMatBeg,
1199
+ csr->rowMatIdx, csr->rowMatElem, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_32I,
1200
+ CUSPARSE_INDEX_BASE_ZERO, CudaComputeType));
1201
+ #endif
1202
+
1203
+ return 0;
1204
+ }
1205
+
1206
+ void dense2csr(CUPDLPcsr *csr, CUPDLPdense *dense) {
1207
+ csr->nRows = dense->nRows;
1208
+ csr->nCols = dense->nCols;
1209
+
1210
+ cupdlp_int nnz = 0;
1211
+ cupdlp_int iCol = 0;
1212
+ cupdlp_int iRow = 0;
1213
+ csr->rowMatBeg[0] = 0;
1214
+ for (iRow = 0; iRow < csr->nRows; ++iRow) {
1215
+ for (iCol = 0; iCol < csr->nCols; ++iCol) {
1216
+ if (dense->data[iCol * csr->nRows + iRow] != 0) {
1217
+ csr->rowMatIdx[nnz] = iCol;
1218
+ csr->rowMatElem[nnz] = dense->data[iCol * csr->nRows + iRow];
1219
+ ++nnz;
1220
+ }
1221
+ }
1222
+ csr->rowMatBeg[iRow + 1] = nnz;
1223
+ }
1224
+ csr->nMatElem = nnz;
1225
+
1226
+ return;
1227
+ }
1228
+
1229
+ void dense2csc(CUPDLPcsc *csc, CUPDLPdense *dense) {
1230
+ csc->nRows = dense->nRows;
1231
+ csc->nCols = dense->nCols;
1232
+
1233
+ cupdlp_int nnz = 0;
1234
+ cupdlp_int iCol = 0;
1235
+ cupdlp_int iRow = 0;
1236
+ csc->colMatBeg[0] = 0;
1237
+ for (iCol = 0; iCol < csc->nCols; ++iCol) {
1238
+ for (iRow = 0; iRow < csc->nRows; ++iRow) {
1239
+ if (dense->data[iCol * csc->nRows + iRow] != 0) {
1240
+ csc->colMatIdx[nnz] = iRow;
1241
+ csc->colMatElem[nnz] = dense->data[iCol * csc->nRows + iRow];
1242
+ ++nnz;
1243
+ }
1244
+ }
1245
+ csc->colMatBeg[iCol + 1] = nnz;
1246
+ }
1247
+
1248
+ csc->nMatElem = nnz;
1249
+
1250
+ return;
1251
+ }
1252
+
1253
+ void csr2dense(CUPDLPdense *dense, CUPDLPcsr *csr) {
1254
+ dense->nRows = csr->nRows;
1255
+ dense->nCols = csr->nCols;
1256
+
1257
+ cupdlp_int iRow = 0;
1258
+ cupdlp_int iCol = 0;
1259
+ cupdlp_int iMatElem = 0;
1260
+ for (iRow = 0; iRow < dense->nRows; ++iRow)
1261
+ for (iCol = 0; iCol < dense->nCols; ++iCol) {
1262
+ if (iCol == csr->rowMatIdx[iMatElem]) {
1263
+ dense->data[iRow * dense->nCols + iCol] = csr->rowMatElem[iMatElem];
1264
+ ++iMatElem;
1265
+ } else {
1266
+ dense->data[iRow * dense->nCols + iCol] = 0;
1267
+ }
1268
+ }
1269
+
1270
+ return;
1271
+ }
1272
+
1273
+ void csc2dense(CUPDLPdense *dense, CUPDLPcsc *csc) {
1274
+ dense->nRows = csc->nRows;
1275
+ dense->nCols = csc->nCols;
1276
+
1277
+ cupdlp_int iRow = 0;
1278
+ cupdlp_int iCol = 0;
1279
+ cupdlp_int iMatElem = 0;
1280
+ for (iCol = 0; iCol < dense->nCols; ++iCol)
1281
+ for (iRow = 0; iRow < dense->nRows; ++iRow) {
1282
+ if (iRow == csc->colMatIdx[iMatElem]) {
1283
+ dense->data[iRow * dense->nCols + iCol] = csc->colMatElem[iMatElem];
1284
+ ++iMatElem;
1285
+ } else {
1286
+ dense->data[iRow * dense->nCols + iCol] = 0;
1287
+ }
1288
+ }
1289
+
1290
+ return;
1291
+ }
1292
+
1293
+ cupdlp_retcode dense_create(CUPDLPdense **dense) {
1294
+ cupdlp_retcode retcode = RETCODE_OK;
1295
+ CUPDLP_INIT_DENSE_MATRIX(*dense, 1);
1296
+
1297
+ exit_cleanup:
1298
+ return retcode;
1299
+ }
1300
+
1301
+ cupdlp_retcode csr_create(CUPDLPcsr **csr) {
1302
+ cupdlp_retcode retcode = RETCODE_OK;
1303
+ CUPDLP_INIT_CSR_MATRIX(*csr, 1);
1304
+
1305
+ exit_cleanup:
1306
+ return retcode;
1307
+ }
1308
+
1309
+ cupdlp_retcode csc_create(CUPDLPcsc **csc) {
1310
+ cupdlp_retcode retcode = RETCODE_OK;
1311
+ CUPDLP_INIT_CSC_MATRIX(*csc, 1);
1312
+
1313
+ exit_cleanup:
1314
+ return retcode;
1315
+ }
1316
+
1317
+ cupdlp_retcode dense_alloc_matrix(CUPDLPdense *dense, cupdlp_int nRows,
1318
+ cupdlp_int nCols, void *src,
1319
+ CUPDLP_MATRIX_FORMAT src_matrix_format) {
1320
+ cupdlp_retcode retcode = RETCODE_OK;
1321
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(dense->data, nRows * nCols);
1322
+
1323
+ switch (src_matrix_format) {
1324
+ case DENSE:
1325
+ dense_copy(dense, (CUPDLPdense *)src);
1326
+ break;
1327
+ case CSR:
1328
+ csr2dense(dense, (CUPDLPcsr *)src);
1329
+ break;
1330
+ case CSC:
1331
+ csc2dense(dense, (CUPDLPcsc *)src);
1332
+ break;
1333
+ default:
1334
+ break;
1335
+ }
1336
+ exit_cleanup:
1337
+ return retcode;
1338
+ }
1339
+
1340
+ cupdlp_retcode csr_alloc_matrix(CUPDLPcsr *csr, cupdlp_int nRows,
1341
+ cupdlp_int nCols, void *src,
1342
+ CUPDLP_MATRIX_FORMAT src_matrix_format) {
1343
+ cupdlp_retcode retcode = RETCODE_OK;
1344
+ cupdlp_int nnz = 0;
1345
+ switch (src_matrix_format) {
1346
+ case DENSE:
1347
+ nnz = nRows * nCols;
1348
+ break;
1349
+ case CSR:
1350
+ nnz = ((CUPDLPcsr *)src)->nMatElem;
1351
+ break;
1352
+ case CSC:
1353
+ nnz = ((CUPDLPcsc *)src)->nMatElem;
1354
+ break;
1355
+ default:
1356
+ break;
1357
+ }
1358
+ // todo make sure this is right
1359
+ CUPDLP_INIT_ZERO_INT_VEC(csr->rowMatBeg, nRows + 1);
1360
+ CUPDLP_INIT_ZERO_INT_VEC(csr->rowMatIdx, nnz);
1361
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(csr->rowMatElem, nnz);
1362
+
1363
+ switch (src_matrix_format) {
1364
+ case DENSE:
1365
+ dense2csr(csr, (CUPDLPdense *)src);
1366
+ break;
1367
+ case CSR:
1368
+ csr_copy(csr, (CUPDLPcsr *)src);
1369
+ break;
1370
+ case CSC:
1371
+ csc2csr(csr, (CUPDLPcsc *)src);
1372
+ break;
1373
+ default:
1374
+ break;
1375
+ }
1376
+ exit_cleanup:
1377
+ return retcode;
1378
+ }
1379
+
1380
+ cupdlp_retcode csc_alloc_matrix(CUPDLPcsc *csc, cupdlp_int nRows,
1381
+ cupdlp_int nCols, void *src,
1382
+ CUPDLP_MATRIX_FORMAT src_matrix_format) {
1383
+ cupdlp_retcode retcode = RETCODE_OK;
1384
+ cupdlp_int nnz = 0;
1385
+ switch (src_matrix_format) {
1386
+ case DENSE:
1387
+ nnz = nRows * nCols;
1388
+ break;
1389
+ case CSR:
1390
+ nnz = ((CUPDLPcsr *)src)->nMatElem;
1391
+ break;
1392
+ case CSC:
1393
+ nnz = ((CUPDLPcsc *)src)->nMatElem;
1394
+ break;
1395
+ default:
1396
+ break;
1397
+ }
1398
+ CUPDLP_INIT_ZERO_INT_VEC(csc->colMatBeg, nCols + 1);
1399
+ CUPDLP_INIT_ZERO_INT_VEC(csc->colMatIdx, nnz);
1400
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(csc->colMatElem, nnz);
1401
+
1402
+ switch (src_matrix_format) {
1403
+ case DENSE:
1404
+ dense2csc(csc, (CUPDLPdense *)src);
1405
+ break;
1406
+ case CSR:
1407
+ csr2csc(csc, (CUPDLPcsr *)src);
1408
+ break;
1409
+ case CSC:
1410
+ csc_copy(csc, (CUPDLPcsc *)src);
1411
+ break;
1412
+ default:
1413
+ break;
1414
+ }
1415
+ exit_cleanup:
1416
+ return retcode;
1417
+ }
1418
+
1419
+ cupdlp_retcode dense_alloc(CUPDLPdense *dense, cupdlp_int nRows,
1420
+ cupdlp_int nCols, cupdlp_float *val) {
1421
+ cupdlp_retcode retcode = RETCODE_OK;
1422
+ dense->nRows = nRows;
1423
+ dense->nCols = nCols;
1424
+ dense->data = cupdlp_NULL;
1425
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(dense->data, nRows * nCols);
1426
+
1427
+ CUPDLP_COPY_VEC(dense->data, val, cupdlp_float, nRows * nCols);
1428
+ exit_cleanup:
1429
+ return retcode;
1430
+ }
1431
+
1432
+ cupdlp_retcode csr_alloc(CUPDLPcsr *csr, cupdlp_int nRows, cupdlp_int nCols,
1433
+ cupdlp_int nnz, cupdlp_int *row_ptr,
1434
+ cupdlp_int *col_ind, cupdlp_float *val) {
1435
+ cupdlp_retcode retcode = RETCODE_OK;
1436
+ csr->nRows = nRows;
1437
+ csr->nCols = nCols;
1438
+ csr->nMatElem = nnz;
1439
+ csr->rowMatBeg = cupdlp_NULL;
1440
+ csr->rowMatIdx = cupdlp_NULL;
1441
+ csr->rowMatElem = cupdlp_NULL;
1442
+
1443
+ CUPDLP_INIT_ZERO_INT_VEC(csr->rowMatBeg, nRows + 1);
1444
+ CUPDLP_INIT_ZERO_INT_VEC(csr->rowMatIdx, nnz);
1445
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(csr->rowMatElem, nnz);
1446
+
1447
+ CUPDLP_COPY_VEC(csr->rowMatBeg, row_ptr, cupdlp_int, nRows + 1);
1448
+ CUPDLP_COPY_VEC(csr->rowMatIdx, col_ind, cupdlp_int, nnz);
1449
+ CUPDLP_COPY_VEC(csr->rowMatElem, val, cupdlp_float, nnz);
1450
+ exit_cleanup:
1451
+ return retcode;
1452
+ }
1453
+
1454
+ cupdlp_retcode csc_alloc(CUPDLPcsc *csc, cupdlp_int nRows, cupdlp_int nCols,
1455
+ cupdlp_int nnz, cupdlp_int *col_ptr,
1456
+ cupdlp_int *row_ind, cupdlp_float *val) {
1457
+ cupdlp_retcode retcode = RETCODE_OK;
1458
+ csc->nRows = nRows;
1459
+ csc->nCols = nCols;
1460
+ csc->nMatElem = nnz;
1461
+ csc->colMatBeg = cupdlp_NULL;
1462
+ csc->colMatIdx = cupdlp_NULL;
1463
+ csc->colMatElem = cupdlp_NULL;
1464
+ CUPDLP_INIT_ZERO_INT_VEC(csc->colMatBeg, nCols + 1);
1465
+ CUPDLP_INIT_ZERO_INT_VEC(csc->colMatIdx, nnz);
1466
+ CUPDLP_INIT_ZERO_DOUBLE_VEC(csc->colMatElem, nnz);
1467
+
1468
+ CUPDLP_COPY_VEC(csc->colMatBeg, col_ptr, cupdlp_int, nCols + 1);
1469
+ CUPDLP_COPY_VEC(csc->colMatIdx, row_ind, cupdlp_int, nnz);
1470
+ CUPDLP_COPY_VEC(csc->colMatElem, val, cupdlp_float, nnz);
1471
+ exit_cleanup:
1472
+ return retcode;
1473
+ }
1474
+
1475
+ void vecPrint(const char *s, const cupdlp_float *a, cupdlp_int n) {
1476
+ cupdlp_printf("%s: ", s);
1477
+ for (cupdlp_int i = 0; i < n; ++i) {
1478
+ cupdlp_printf("%.3f ", a[i]);
1479
+ }
1480
+ cupdlp_printf("\n");
1481
+ }
1482
+
1483
+ void vecIntPrint(const char *s, const cupdlp_int *a, cupdlp_int n) {
1484
+ cupdlp_printf("%s: ", s);
1485
+ for (cupdlp_int i = 0; i < n; ++i) {
1486
+ cupdlp_printf("%d ", a[i]);
1487
+ }
1488
+ cupdlp_printf("\n");
1489
+ }
1490
+
1491
+ void PDHG_Dump_Stats(CUPDLPwork *w) {
1492
+ cupdlp_int nCols = w->iterates->nCols;
1493
+ cupdlp_int nRows = w->iterates->nRows;
1494
+ CUPDLPiterates *iterates = w->iterates;
1495
+ CUPDLPstepsize *stepsize = w->stepsize;
1496
+
1497
+ cupdlp_printf("------------------------------------------------\n");
1498
+ cupdlp_printf("Iteration % 3d\n", w->timers->nIter);
1499
+ #if CUPDLP_DUMP_ITERATES
1500
+ vecPrint("x", iterates->x->data, nCols);
1501
+ vecPrint("y", iterates->y->data, nRows);
1502
+ vecPrint("xSum", iterates->xSum, nCols);
1503
+ vecPrint("ySum", iterates->ySum, nRows);
1504
+ vecPrint("Ax ", iterates->ax->data, nRows);
1505
+ vecPrint("A'y", iterates->aty->data, nCols);
1506
+ vecPrint("xLastRestart", iterates->xLastRestart, nCols);
1507
+ vecPrint("yLastRestart", iterates->yLastRestart, nRows);
1508
+ #endif
1509
+ cupdlp_printf(
1510
+ "PrimalStep: %e, SumPrimalStep: %e, DualStep: %e, SumDualStep: %e\n",
1511
+ stepsize->dPrimalStep, stepsize->dSumPrimalStep, stepsize->dDualStep,
1512
+ stepsize->dSumDualStep);
1513
+ cupdlp_printf("Stepsize: %e, Primal weight: %e Ratio: %e\n",
1514
+ sqrt(stepsize->dPrimalStep * stepsize->dDualStep),
1515
+ sqrt(stepsize->dBeta), stepsize->dTheta);
1516
+ }
1517
+
1518
+ void csrPrintDense(const char *s, CUPDLPcsr *csr) {
1519
+ cupdlp_printf("------------------------------------------------\n");
1520
+ cupdlp_printf("%s:\n", s);
1521
+ cupdlp_int deltaCol = 0;
1522
+ for (cupdlp_int iRow = 0; iRow < csr->nRows; ++iRow) {
1523
+ for (cupdlp_int iElem = csr->rowMatBeg[iRow];
1524
+ iElem < csr->rowMatBeg[iRow + 1]; ++iElem) {
1525
+ if (iElem == csr->rowMatBeg[iRow])
1526
+ deltaCol = csr->rowMatIdx[iElem];
1527
+ else
1528
+ deltaCol = csr->rowMatIdx[iElem] - csr->rowMatIdx[iElem - 1] - 1;
1529
+ for (cupdlp_int i = 0; i < deltaCol; ++i) {
1530
+ cupdlp_printf(" ");
1531
+ }
1532
+ cupdlp_printf("%6.3f ", csr->rowMatElem[iElem]);
1533
+ }
1534
+ cupdlp_printf("\n");
1535
+ }
1536
+ cupdlp_printf("------------------------------------------------\n");
1537
+ }
1538
+
1539
+ void cscPrintDense(const char *s, CUPDLPcsc *csc) {
1540
+ cupdlp_printf("------------------------------------------------\n");
1541
+ cupdlp_printf("%s (Trans):\n", s);
1542
+ cupdlp_int deltaRow = 0;
1543
+ for (cupdlp_int iCol = 0; iCol < csc->nCols; ++iCol) {
1544
+ for (cupdlp_int iElem = csc->colMatBeg[iCol];
1545
+ iElem < csc->colMatBeg[iCol + 1]; ++iElem) {
1546
+ if (iElem == csc->colMatBeg[iCol])
1547
+ deltaRow = csc->colMatIdx[iElem];
1548
+ else
1549
+ deltaRow = csc->colMatIdx[iElem] - csc->colMatIdx[iElem - 1] - 1;
1550
+ for (cupdlp_int i = 0; i < deltaRow; ++i) {
1551
+ cupdlp_printf(" ");
1552
+ }
1553
+ cupdlp_printf("%6.3f ", csc->colMatElem[iElem]);
1554
+ }
1555
+ cupdlp_printf("\n");
1556
+ }
1557
+ cupdlp_printf("------------------------------------------------\n");
1558
+ }
1559
+
1560
+ #ifndef CUPDLP_OUTPUT_NAMES
1561
+ const char *termCodeNames[] = {"OPTIMAL",
1562
+ "INFEASIBLE",
1563
+ "UNBOUNDED",
1564
+ "INFEASIBLE_OR_UNBOUNDED",
1565
+ "TIMELIMIT_OR_ITERLIMIT",
1566
+ "FEASIBLE"};
1567
+ const char *termIterateNames[] = {
1568
+ "LAST_ITERATE",
1569
+ "AVERAGE_ITERATE",
1570
+ };
1571
+ #endif
1572
+
1573
+ void writeJson(const char *fout, CUPDLPwork *work) {
1574
+ FILE *fptr;
1575
+
1576
+ cupdlp_printf("--------------------------------\n");
1577
+ cupdlp_printf("--- saving to %s\n", fout);
1578
+ cupdlp_printf("--------------------------------\n");
1579
+ // Open a file in writing mode
1580
+ fptr = fopen(fout, "w");
1581
+
1582
+ fprintf(fptr, "{");
1583
+
1584
+ // solver
1585
+ fprintf(fptr, "\"solver\":\"%s\",", "cuPDLP-C");
1586
+
1587
+ // timers
1588
+ fprintf(fptr, "\"nIter\":%d,", work->timers->nIter);
1589
+ fprintf(fptr, "\"nAtyCalls\":%d,", work->timers->nAtyCalls);
1590
+ fprintf(fptr, "\"nAxCalls\":%d,", work->timers->nAxCalls);
1591
+ fprintf(fptr, "\"dSolvingBeg\":%f,", work->timers->dSolvingBeg);
1592
+ fprintf(fptr, "\"dSolvingTime\":%f,", work->timers->dSolvingTime);
1593
+ fprintf(fptr, "\"dPresolveTime\":%f,", work->timers->dPresolveTime);
1594
+ fprintf(fptr, "\"dScalingTime\":%f,", work->timers->dScalingTime);
1595
+ #ifndef CUPDLP_CPU
1596
+ fprintf(fptr, "\"AllocMem_CopyMatToDeviceTime\":%f,",
1597
+ work->timers->AllocMem_CopyMatToDeviceTime);
1598
+ fprintf(fptr, "\"CopyVecToDeviceTime\":%f,",
1599
+ work->timers->CopyVecToDeviceTime);
1600
+ fprintf(fptr, "\"CopyVecToHostTime\":%f,", work->timers->CopyVecToHostTime);
1601
+ fprintf(fptr, "\"DeviceMatVecProdTime\":%f,",
1602
+ work->timers->DeviceMatVecProdTime);
1603
+ #endif
1604
+ // residuals
1605
+ fprintf(fptr, "\"dPrimalObj\":%.14f,", work->resobj->dPrimalObj);
1606
+ fprintf(fptr, "\"dDualObj\":%.14f,", work->resobj->dDualObj);
1607
+ fprintf(fptr, "\"dPrimalFeas\":%.14f,", work->resobj->dPrimalFeas);
1608
+ fprintf(fptr, "\"dDualFeas\":%.14f,", work->resobj->dDualFeas);
1609
+ fprintf(fptr, "\"dPrimalObjAverage\":%.14f,",
1610
+ work->resobj->dPrimalObjAverage);
1611
+ fprintf(fptr, "\"dDualObjAverage\":%.14f,", work->resobj->dDualObjAverage);
1612
+ fprintf(fptr, "\"dPrimalFeasAverage\":%.14f,",
1613
+ work->resobj->dPrimalFeasAverage);
1614
+ fprintf(fptr, "\"dDualFeasAverage\":%.14f,", work->resobj->dDualFeasAverage);
1615
+ fprintf(fptr, "\"dDualityGap\":%.14f,", work->resobj->dDualityGap);
1616
+ fprintf(fptr, "\"dDualityGapAverage\":%.14f,",
1617
+ work->resobj->dDualityGapAverage);
1618
+ // fprintf(fptr, "\"dComplementarity\":%.14f,",
1619
+ // work->resobj->dComplementarity); fprintf(fptr,
1620
+ // "\"dComplementarityAverage\":%.14f,",
1621
+ // work->resobj->dComplementarityAverage);
1622
+
1623
+ // todo should this be added to postsolve?
1624
+ // todo, fix dNormCost and this
1625
+ if (work->resobj->termIterate == AVERAGE_ITERATE) {
1626
+ fprintf(fptr, "\"dRelPrimalFeas\":%.14f,",
1627
+ work->resobj->dPrimalFeasAverage / (1.0 + work->scaling->dNormRhs));
1628
+ fprintf(fptr, "\"dRelDualFeas\":%.14f,",
1629
+ work->resobj->dDualFeasAverage / (1.0 + work->scaling->dNormCost));
1630
+ fprintf(fptr, "\"dRelDualityGap\":%.14f,", work->resobj->dRelObjGapAverage);
1631
+ } else {
1632
+ fprintf(fptr, "\"dRelPrimalFeas\":%.14f,",
1633
+ work->resobj->dPrimalFeas / (1.0 + work->scaling->dNormRhs));
1634
+ fprintf(fptr, "\"dRelDualFeas\":%.14f,",
1635
+ work->resobj->dDualFeas / (1.0 + work->scaling->dNormCost));
1636
+ fprintf(fptr, "\"dRelDualityGap\":%.14f,", work->resobj->dRelObjGap);
1637
+ }
1638
+ fprintf(fptr, "\"terminationCode\":\"%s\",",
1639
+ termCodeNames[work->resobj->termCode]);
1640
+ fprintf(fptr, "\"terminationIterate\":\"%s\",",
1641
+ termIterateNames[work->resobj->termIterate]);
1642
+ fprintf(fptr, "\"primalCode\":\"%s\",",
1643
+ termCodeNames[work->resobj->primalCode]);
1644
+ fprintf(fptr, "\"dualCode\":\"%s\",", termCodeNames[work->resobj->dualCode]);
1645
+ fprintf(fptr, "\"terminationInfeasIterate\":\"%s\"",
1646
+ termIterateNames[work->resobj->termInfeasIterate]);
1647
+
1648
+ fprintf(fptr, "}");
1649
+ // Close the file
1650
+ fclose(fptr);
1651
+ }
1652
+
1653
+ void writeSol(const char *fout, cupdlp_int nCols, cupdlp_int nRows,
1654
+ cupdlp_float *col_value, cupdlp_float *col_dual,
1655
+ cupdlp_float *row_value, cupdlp_float *row_dual) {
1656
+ FILE *fptr;
1657
+
1658
+ cupdlp_printf("--------------------------------\n");
1659
+ cupdlp_printf("--- saving sol to %s\n", fout);
1660
+ cupdlp_printf("--------------------------------\n");
1661
+ // Open a file in writing mode
1662
+ fptr = fopen(fout, "w");
1663
+ fprintf(fptr, "{");
1664
+
1665
+ // nCols
1666
+ fprintf(fptr, "\n");
1667
+
1668
+ fprintf(fptr, "\"nCols\": %d", nCols);
1669
+
1670
+ // nRows
1671
+ fprintf(fptr, ",\n");
1672
+
1673
+ fprintf(fptr, "\"nRows\": %d", nRows);
1674
+
1675
+ // col value
1676
+ fprintf(fptr, ",\n");
1677
+
1678
+ fprintf(fptr, "\"col_value\": [");
1679
+ if (col_value && nCols) {
1680
+ for (int i = 0; i < nCols - 1; ++i) {
1681
+ fprintf(fptr, "%.14f,", col_value[i]);
1682
+ }
1683
+ fprintf(fptr, "%.14f", col_value[nCols - 1]);
1684
+ }
1685
+ fprintf(fptr, "]");
1686
+
1687
+ // col dual
1688
+ fprintf(fptr, ",\n");
1689
+ fprintf(fptr, "\"col_dual\": [");
1690
+ if (col_dual && nCols) {
1691
+ for (int i = 0; i < nCols - 1; ++i) {
1692
+ fprintf(fptr, "%.14f,", col_dual[i]);
1693
+ }
1694
+ fprintf(fptr, "%.14f", col_dual[nCols - 1]);
1695
+ }
1696
+ fprintf(fptr, "]");
1697
+
1698
+ // row value
1699
+ fprintf(fptr, ",\n");
1700
+ fprintf(fptr, "\"row_value\": [");
1701
+ if (row_value && nRows) {
1702
+ for (int i = 0; i < nRows - 1; ++i) {
1703
+ fprintf(fptr, "%.14f,", row_value[i]);
1704
+ }
1705
+ fprintf(fptr, "%.14f", row_value[nRows - 1]);
1706
+ }
1707
+ fprintf(fptr, "]");
1708
+
1709
+ // row dual
1710
+ fprintf(fptr, ",\n");
1711
+ fprintf(fptr, "\"row_dual\": [");
1712
+ if (row_dual && nRows) {
1713
+ for (int i = 0; i < nRows - 1; ++i) {
1714
+ fprintf(fptr, "%.14f,", row_dual[i]);
1715
+ }
1716
+ fprintf(fptr, "%.14f", row_dual[nRows - 1]);
1717
+ }
1718
+ fprintf(fptr, "]");
1719
+
1720
+ // end writing
1721
+ fprintf(fptr, "\n");
1722
+ fprintf(fptr, "}");
1723
+
1724
+ // Close the file
1725
+ fclose(fptr);
1726
+ }