or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdcore-solver.mddata-updates.mdindex.mdmixed-integer.md

data-updates.mddocs/

0

# Problem Data Updates

1

2

The ECOS library provides expert-level interfaces for updating problem data during solve iterations without requiring complete problem re-setup. This is particularly useful for applications requiring real-time optimization with changing parameters, such as model predictive control.

3

4

## Capabilities

5

6

### Core Solver Data Updates

7

8

Update individual elements of the problem data vectors for continuous SOCP problems.

9

10

```c { .api }

11

void ecos_updateDataEntry_h(pwork* w, idxint idx, pfloat value);

12

void ecos_updateDataEntry_c(pwork* w, idxint idx, pfloat value);

13

```

14

15

**Parameters:**

16

- `w`: Solver workspace from ECOS_setup

17

- `idx`: Index of element to update (0-based)

18

- `value`: New value for the element

19

20

**Usage Example:**

21

22

```c

23

// Initial problem setup

24

pwork* work = ECOS_setup(n, m, p, l, ncones, q,

25

Gpr, Gjc, Gir, Apr, Ajc, Air,

26

c, h, b);

27

28

// Solve initial problem

29

idxint exitflag = ECOS_solve(work);

30

31

// Update objective coefficient c[1] = 2.5

32

ecos_updateDataEntry_c(work, 1, 2.5);

33

34

// Update inequality RHS h[0] = 1.2

35

ecos_updateDataEntry_h(work, 0, 1.2);

36

37

// Solve updated problem (warm start from previous solution)

38

exitflag = ECOS_solve(work);

39

40

printf("Updated objective: %f\\n", work->info->pcost);

41

```

42

43

### Mixed-Integer Solver Data Updates

44

45

Update problem data elements for mixed-integer problems.

46

47

```c { .api }

48

void updateDataEntry_h(ecos_bb_pwork* w, idxint idx, pfloat value);

49

void updateDataEntry_c(ecos_bb_pwork* w, idxint idx, pfloat value);

50

```

51

52

**Parameters:**

53

- `w`: Mixed-integer solver workspace from ECOS_BB_setup

54

- `idx`: Index of element to update (0-based)

55

- `value`: New value for the element

56

57

**Usage Example:**

58

59

```c

60

// Initial mixed-integer problem setup

61

ecos_bb_pwork* work = ECOS_BB_setup(n, m, p, l, ncones, q,

62

Gpr, Gjc, Gir, Apr, Ajc, Air,

63

c, h, b,

64

num_bool_vars, bool_vars_idx,

65

num_int_vars, int_vars_idx,

66

stgs);

67

68

// Solve initial problem

69

idxint exitflag = ECOS_BB_solve(work);

70

71

// Update problem data for next iteration

72

updateDataEntry_c(work, 0, 3.0); // Update objective coefficient

73

updateDataEntry_h(work, 2, 0.8); // Update constraint bound

74

75

// Solve updated mixed-integer problem

76

exitflag = ECOS_BB_solve(work);

77

78

printf("Updated integer solution objective: %f\\n", work->info->pcost);

79

```

80

81

## Data Update Behavior

82

83

### Equilibration Handling

84

85

The update functions automatically handle equilibration scaling:

86

87

```c

88

// The value is stored in equilibrated form internally

89

ecos_updateDataEntry_h(work, idx, value);

90

91

// Equivalent to:

92

// work->h[idx] = value * equilibration_factor[idx];

93

```

94

95

### Supported Data Vectors

96

97

**Updatable vectors:**

98

- `c`: Objective vector coefficients

99

- `h`: Inequality constraint RHS vector

100

101

**Non-updatable data:**

102

- Matrix structure (A, G sparsity patterns)

103

- Matrix values (Apr, Gpr arrays)

104

- Equality constraint RHS (b vector)

105

- Problem dimensions and cone structure

106

107

### Warm Starting

108

109

After data updates, the solver uses the previous solution as a warm start:

110

111

```c

112

// First solve

113

ECOS_solve(work);

114

pfloat* previous_x = work->x; // Store previous solution

115

116

// Update data

117

ecos_updateDataEntry_c(work, 0, new_value);

118

119

// Second solve starts from previous_x

120

ECOS_solve(work); // Typically converges faster

121

```

122

123

## Common Usage Patterns

124

125

### Model Predictive Control (MPC)

126

127

```c

128

// MPC horizon optimization loop

129

for (int k = 0; k < horizon_steps; k++) {

130

// Update objective based on current state

131

for (int i = 0; i < n; i++) {

132

pfloat new_coeff = compute_objective_coeff(current_state, i, k);

133

ecos_updateDataEntry_c(work, i, new_coeff);

134

}

135

136

// Update constraint bounds based on current measurements

137

for (int i = 0; i < m; i++) {

138

pfloat new_bound = compute_constraint_bound(measurements, i, k);

139

ecos_updateDataEntry_h(work, i, new_bound);

140

}

141

142

// Solve updated problem

143

idxint status = ECOS_solve(work);

144

145

if (status == ECOS_OPTIMAL) {

146

// Apply first control input

147

apply_control(work->x[0]);

148

149

// Update state estimate

150

update_state(work->x);

151

} else {

152

printf("MPC solve failed at step %d\\n", k);

153

break;

154

}

155

}

156

```

157

158

### Parameter Sweeps

159

160

```c

161

// Sweep over different objective weights

162

pfloat weights[] = {0.1, 0.5, 1.0, 2.0, 5.0};

163

int num_weights = sizeof(weights) / sizeof(pfloat);

164

165

for (int i = 0; i < num_weights; i++) {

166

// Update objective coefficient

167

ecos_updateDataEntry_c(work, target_idx, weights[i]);

168

169

// Solve with new weight

170

idxint status = ECOS_solve(work);

171

172

if (status == ECOS_OPTIMAL) {

173

printf("Weight %f: objective = %f\\n",

174

weights[i], work->info->pcost);

175

176

// Store solution for analysis

177

store_solution(weights[i], work->x, work->info->pcost);

178

}

179

}

180

```

181

182

### Robust Optimization

183

184

```c

185

// Solve for different uncertainty realizations

186

pfloat uncertainty_samples[100];

187

generate_uncertainty_samples(uncertainty_samples, 100);

188

189

pfloat best_objective = INFINITY;

190

pfloat* best_solution = malloc(n * sizeof(pfloat));

191

192

for (int sample = 0; sample < 100; sample++) {

193

// Update constraint bound based on uncertainty

194

pfloat uncertain_bound = nominal_bound + uncertainty_samples[sample];

195

ecos_updateDataEntry_h(work, uncertain_constraint_idx, uncertain_bound);

196

197

// Solve robust subproblem

198

idxint status = ECOS_solve(work);

199

200

if (status == ECOS_OPTIMAL) {

201

if (work->info->pcost < best_objective) {

202

best_objective = work->info->pcost;

203

memcpy(best_solution, work->x, n * sizeof(pfloat));

204

}

205

}

206

}

207

208

printf("Best robust objective: %f\\n", best_objective);

209

```

210

211

## Performance Considerations

212

213

### Update Frequency

214

215

- **High-frequency updates**: Suitable for real-time applications (kHz rates)

216

- **Batch updates**: More efficient to update multiple elements before resolving

217

- **Structure preservation**: Matrix sparsity patterns cannot change

218

219

### Memory Usage

220

221

```c

222

// Updates are in-place - no additional memory allocation

223

ecos_updateDataEntry_h(work, idx, value); // O(1) operation

224

225

// Original data can be restored if needed

226

pfloat original_h_value = original_h[idx];

227

ecos_updateDataEntry_h(work, idx, original_h_value);

228

```

229

230

### Solver Warm-Starting

231

232

The solver automatically warm-starts from the previous solution:

233

234

```c

235

// Monitor warm-start effectiveness

236

int iterations_before = work->info->iter;

237

ecos_updateDataEntry_c(work, 0, new_value);

238

ECOS_solve(work);

239

int iterations_after = work->info->iter;

240

241

printf("Warm start reduced iterations: %d -> %d\\n",

242

iterations_before, iterations_after);

243

```

244

245

## Limitations and Considerations

246

247

### Matrix Structure

248

249

Matrix sparsity patterns and dimensions cannot be changed:

250

251

```c

252

// These operations are NOT supported:

253

// - Changing Apr, Gpr, Ajc, Gjc, Air, Gir arrays

254

// - Modifying problem dimensions n, m, p

255

// - Altering cone structure (l, ncones, q)

256

```

257

258

### Equilibration Effects

259

260

Updates may trigger re-equilibration in some cases:

261

262

```c

263

// Large magnitude changes may affect numerical conditioning

264

ecos_updateDataEntry_h(work, idx, 1e6 * original_value); // May cause issues

265

```

266

267

### Thread Safety

268

269

Update functions are not thread-safe:

270

271

```c

272

// Single-threaded usage only

273

ecos_updateDataEntry_c(work, idx, value);

274

275

// For multi-threaded applications, use locks or separate workspaces

276

```

277

278

## Error Handling

279

280

```c

281

// Validate index bounds before updating

282

if (idx >= 0 && idx < work->n) {

283

ecos_updateDataEntry_c(work, idx, value);

284

} else {

285

printf("Invalid objective index: %d\\n", idx);

286

}

287

288

if (idx >= 0 && idx < work->m) {

289

ecos_updateDataEntry_h(work, idx, value);

290

} else {

291

printf("Invalid constraint index: %d\\n", idx);

292

}

293

294

// Check solver status after updates

295

idxint status = ECOS_solve(work);

296

if (status != ECOS_OPTIMAL) {

297

printf("Solver failed after data update, status: %d\\n", status);

298

// Consider reverting to previous data or adjusting tolerances

299

}

300

```