Skip to content

Commit 27a5b63

Browse files
committed
wip
1 parent da03867 commit 27a5b63

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

highs/pdlp/hipdlp/defs.hpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#ifndef HIGHS_PDLP_DEFS_HPP
2+
#define HIGHS_PDLP_DEFS_HPP
3+
4+
#include <cmath>
5+
#include <vector>
6+
#include "Highs.h"
7+
8+
enum class Device { CPU, GPU };
9+
10+
enum class ScalingMethod { NONE, RUIZ, POCK_CHAMBOLLE, L2_NORM, COMBINED };
11+
12+
enum class RestartStrategy { NO_RESTART, FIXED_RESTART, ADAPTIVE_RESTART };
13+
14+
enum class StepSizeStrategy { FIXED, ADAPTIVE, MALITSKY_POCK };
15+
16+
struct MalitskyPockParams {
17+
double step_size_interpolation = 0.5; // Between 0 and 1
18+
double step_size_downscaling_factor = 0.7;
19+
double linesearch_contraction_factor = 0.99;
20+
void initialise();
21+
};
22+
23+
struct AdaptiveLinesearchParams {
24+
double step_size_reduction_exponent = 0.3;
25+
double step_size_growth_exponent = 0.6;
26+
void initialise();
27+
};
28+
29+
struct PrimalDualParams {
30+
double eta;
31+
double omega;
32+
double tolerance;
33+
size_t max_iterations;
34+
Device device_type;
35+
double time_limit = 3600.0;
36+
37+
// Restart parameters
38+
RestartStrategy restart_strategy;
39+
int fixed_restart_interval;
40+
41+
bool use_halpern_restart = false;
42+
43+
// Scaling parameters
44+
ScalingMethod scaling_method = ScalingMethod::NONE;
45+
bool use_ruiz_scaling = false;
46+
bool use_pc_scaling = false;
47+
bool use_l2_scaling = false;
48+
49+
// Ruiz scaling parameters
50+
int ruiz_iterations = 10;
51+
double ruiz_norm = INFINITY;
52+
53+
// Pock-Chambolle scaling parameters
54+
double pc_alpha = 1.0;
55+
56+
// Step sizes strategy
57+
StepSizeStrategy step_size_strategy = StepSizeStrategy::FIXED;
58+
59+
MalitskyPockParams malitsky_pock_params;
60+
AdaptiveLinesearchParams adaptive_linesearch_params;
61+
void initialise();
62+
};
63+
64+
struct PdlpIterate {
65+
// Primary variables
66+
std::vector<double> x;
67+
std::vector<double> y;
68+
69+
// Cached matrix-vector products
70+
mutable std::vector<double> Ax;
71+
mutable std::vector<double> Aty;
72+
mutable bool Ax_valid = false;
73+
mutable bool Aty_valid = false;
74+
75+
// Constructors
76+
PdlpIterate() = default;
77+
PdlpIterate(int num_cols, int num_rows)
78+
: x(num_cols, 0.0), y(num_rows, 0.0), Ax(num_rows, 0.0), Aty(num_cols, 0.0) {}
79+
PdlpIterate(const std::vector<double>& x_init, const std::vector<double>& y_init)
80+
: x(x_init), y(y_init), Ax(y_init.size(), 0.0), Aty(x_init.size(), 0.0) {}
81+
82+
// Arithmetic operations
83+
// z = alpha * this + beta * other
84+
void LinearCombination(const PdlpIterate& other, double alpha, double beta);
85+
86+
// this = this + alpha * other
87+
void AddScaled(const PdlpIterate& other, double alpha);
88+
89+
// this = alpha * this
90+
void Scale(double alpha);
91+
92+
// Copy operations
93+
void CopyFrom(const PdlpIterate& other);
94+
PdlpIterate& operator=(const PdlpIterate& other);
95+
96+
// Norms and metrics
97+
double PrimalNorm() const; // ||x||_2
98+
double DualNorm() const; // ||y||_2
99+
double WeightedNorm(double omega) const; // sqrt(||x||_2^2 + omega^2 * ||y||_2^2)
100+
101+
// Distance metrics
102+
double Distance(const PdlpIterate& other, double omega = 1.0) const;
103+
104+
// Matrix-vector product management
105+
void ComputeAx(const HighsLp& lp) const;
106+
void ComputeATy(const HighsLp& lp) const;
107+
void InvalidateProducts(); // Call when x or y change
108+
109+
const std::vector<double>& GetAx(const HighsLp& lp) const;
110+
const std::vector<double>& GetATy(const HighsLp& lp) const;
111+
112+
// For block-structured problems
113+
struct BlockStructure {
114+
std::vector<int> x_block_sizes;
115+
std::vector<int> y_block_sizes;
116+
// std::vector<std::vector<double>> x_blocks; // Future: for block problems
117+
// std::vector<std::vector<double>> y_blocks;
118+
};
119+
120+
// Optional: block structure for future extensions
121+
std::unique_ptr<BlockStructure> block_structure = nullptr;
122+
123+
private:
124+
void EnsureAxComputed(const HighsLp& lp) const;
125+
void EnsureATyComputed(const HighsLp& lp) const;
126+
};
127+
128+
namespace pdlp_iterate_ops {
129+
// Compute z_new = z_old -
130+
};
131+
132+
#endif

0 commit comments

Comments
 (0)