or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-extensions.mdcore-modeling.mddae.mddata-management.mddomain-sets.mdgdp.mdindex.mdmathematical-functions.mdmpec.mdoptimization-interface.md

advanced-extensions.mddocs/

0

# Advanced Extensions

1

2

Contributed modules providing specialized optimization algorithms, solver interfaces, and modeling capabilities in Pyomo. These extensions offer advanced techniques for complex optimization problems including nonlinear decomposition, sensitivity analysis, robust optimization, and specialized solver interfaces.

3

4

## Capabilities

5

6

### Optimization Algorithms

7

8

Advanced optimization algorithms for complex problem types including mixed-integer nonlinear programming and generalized disjunctive programming.

9

10

```python { .api }

11

# GDP Optimization (pyomo.contrib.gdpopt)

12

class GDPoptSolver:

13

"""GDP optimization solver with multiple solution strategies."""

14

def __init__(self, **kwargs): ...

15

def solve(self, model, **kwargs): ...

16

17

# Mixed-Integer Nonlinear Decomposition (pyomo.contrib.mindtpy)

18

class MindtPySolver:

19

"""Mixed-integer nonlinear decomposition algorithm."""

20

def __init__(self, **kwargs): ...

21

def solve(self, model, **kwargs): ...

22

23

# Multi-start Optimization (pyomo.contrib.multistart)

24

class MultistartSolver:

25

"""Multi-start optimization for global optimization."""

26

def __init__(self, **kwargs): ...

27

def solve(self, model, **kwargs): ...

28

29

# Trust Region Methods (pyomo.contrib.trustregion)

30

class TrustRegionSolver:

31

"""Trust region optimization methods."""

32

def __init__(self, **kwargs): ...

33

def solve(self, model, **kwargs): ...

34

```

35

36

### Advanced Solver Interfaces

37

38

Next-generation solver interfaces with enhanced performance and capabilities.

39

40

```python { .api }

41

# Advanced Solver Interface (pyomo.contrib.appsi)

42

class AppsiSolver:

43

"""Advanced solver interface with improved performance."""

44

def __init__(self, solver_name, **kwargs): ...

45

def solve(self, model, **kwargs): ...

46

def update_config(self, **kwargs): ...

47

48

# New Solver Framework (pyomo.contrib.solver)

49

class NewSolverInterface:

50

"""New solver interface framework."""

51

def __init__(self, **kwargs): ...

52

def solve(self, model, **kwargs): ...

53

```

54

55

### Modeling Extensions

56

57

Extended modeling capabilities for specialized problem types and constraint programming.

58

59

```python { .api }

60

# Constraint Programming (pyomo.contrib.cp)

61

class CPModel:

62

"""Constraint programming model extensions."""

63

def __init__(self): ...

64

65

def AllDifferent(variables):

66

"""All different constraint for CP."""

67

68

def Circuit(variables):

69

"""Circuit constraint for routing problems."""

70

71

# Preprocessing (pyomo.contrib.preprocessing)

72

class ModelPreprocessor:

73

"""Model preprocessing and reformulation."""

74

def __init__(self): ...

75

def preprocess(self, model): ...

76

77

# Expression Simplification (pyomo.contrib.simplification)

78

def simplify_expression(expr):

79

"""

80

Simplify mathematical expressions.

81

82

Args:

83

expr: Expression to simplify

84

85

Returns:

86

Expression: Simplified expression

87

"""

88

89

# Piecewise Linear Modeling (pyomo.contrib.piecewise)

90

class PiecewiseLinearFunction:

91

"""Enhanced piecewise linear function modeling."""

92

def __init__(self, **kwargs): ...

93

```

94

95

### Analysis Tools

96

97

Comprehensive analysis tools for model diagnostics, sensitivity analysis, and feasibility analysis.

98

99

```python { .api }

100

# Sensitivity Analysis (pyomo.contrib.sensitivity_toolbox)

101

class SensitivityInterface:

102

"""Sensitivity analysis interface."""

103

def __init__(self, model, **kwargs): ...

104

105

def get_dsdp(self, variables, parameters):

106

"""

107

Get sensitivity of solution w.r.t. parameters.

108

109

Args:

110

variables: Variables of interest

111

parameters: Parameters for sensitivity

112

113

Returns:

114

dict: Sensitivity matrix

115

"""

116

117

# Incidence Analysis (pyomo.contrib.incidence_analysis)

118

def get_incidence_matrix(model):

119

"""

120

Get constraint-variable incidence matrix.

121

122

Args:

123

model: Pyomo model

124

125

Returns:

126

scipy.sparse matrix: Incidence matrix

127

"""

128

129

def analyze_structural_singularity(model):

130

"""

131

Analyze structural singularity of model.

132

133

Args:

134

model: Pyomo model

135

136

Returns:

137

dict: Analysis results

138

"""

139

140

# Feasibility-Based Bounds Tightening (pyomo.contrib.fbbt)

141

def fbbt(model, **kwargs):

142

"""

143

Perform feasibility-based bounds tightening.

144

145

Args:

146

model: Pyomo model to tighten

147

**kwargs: FBBT options

148

149

Returns:

150

dict: Bounds tightening results

151

"""

152

153

# Community Detection (pyomo.contrib.community_detection)

154

def detect_communities(model):

155

"""

156

Detect communities in model structure.

157

158

Args:

159

model: Pyomo model

160

161

Returns:

162

dict: Community structure

163

"""

164

```

165

166

### Specialized Applications

167

168

Domain-specific applications for parameter estimation, robust optimization, design of experiments, and model predictive control.

169

170

```python { .api }

171

# Parameter Estimation (pyomo.contrib.parmest)

172

class ParameterEstimation:

173

"""Parameter estimation interface."""

174

def __init__(self, model_function, data, **kwargs): ...

175

176

def theta_est(self, **kwargs):

177

"""

178

Estimate parameters.

179

180

Returns:

181

dict: Estimated parameters

182

"""

183

184

def likelihood_ratio_test(self, **kwargs):

185

"""

186

Perform likelihood ratio test.

187

188

Returns:

189

dict: Test results

190

"""

191

192

# Robust Optimization (pyomo.contrib.pyros)

193

class PyROSSolver:

194

"""Robust optimization solver."""

195

def __init__(self): ...

196

197

def solve(self, model, uncertain_params, **kwargs):

198

"""

199

Solve robust optimization problem.

200

201

Args:

202

model: Nominal model

203

uncertain_params: Uncertain parameters

204

**kwargs: Solver options

205

206

Returns:

207

Results: Robust solution

208

"""

209

210

# Design of Experiments (pyomo.contrib.doe)

211

class DesignOfExperiments:

212

"""Design of experiments interface."""

213

def __init__(self, model, **kwargs): ...

214

215

def compute_FIM(self, **kwargs):

216

"""

217

Compute Fisher Information Matrix.

218

219

Returns:

220

numpy.array: FIM matrix

221

"""

222

223

def optimize_design(self, **kwargs):

224

"""

225

Optimize experimental design.

226

227

Returns:

228

dict: Optimal design

229

"""

230

231

# Model Predictive Control (pyomo.contrib.mpc)

232

class ModelPredictiveController:

233

"""Model predictive control interface."""

234

def __init__(self, model, **kwargs): ...

235

236

def solve_mpc(self, initial_state, **kwargs):

237

"""

238

Solve MPC optimization.

239

240

Args:

241

initial_state: Current state

242

**kwargs: MPC options

243

244

Returns:

245

dict: Control actions

246

"""

247

```

248

249

### Network Modeling

250

251

Components for modeling network structures and flows in optimization problems including process networks and supply chains.

252

253

```python { .api }

254

# Network Components (pyomo.network)

255

class Arc:

256

"""Network arc component for connecting ports."""

257

def __init__(self, *args, **kwargs): ...

258

259

class Port:

260

"""Connection port component for network modeling."""

261

def __init__(self, *args, **kwargs): ...

262

263

class SequentialDecomposition:

264

"""Sequential decomposition solver for network problems."""

265

def __init__(self, **kwargs): ...

266

def solve(self, model, **kwargs): ...

267

```

268

269

### Numerical Computing Interfaces

270

271

Advanced numerical computing interfaces for integration with external numerical libraries.

272

273

```python { .api }

274

# PyNumero (pyomo.contrib.pynumero)

275

class PyNumeroInterface:

276

"""Interface to advanced numerical methods."""

277

def __init__(self, model): ...

278

279

def get_jacobian(self):

280

"""Get constraint Jacobian matrix."""

281

282

def get_hessian(self):

283

"""Get Lagrangian Hessian matrix."""

284

285

def evaluate_constraints(self, x):

286

"""Evaluate constraints at point x."""

287

```

288

289

## Usage Examples

290

291

### GDP Optimization

292

293

```python

294

from pyomo.environ import *

295

from pyomo.gdp import Disjunct, Disjunction

296

import pyomo.contrib.gdpopt as gdpopt

297

298

# Create GDP model

299

model = ConcreteModel()

300

model.x = Var(bounds=(0, 10))

301

model.y = Var(bounds=(0, 10))

302

303

# Disjuncts

304

model.d1 = Disjunct()

305

model.d1.c1 = Constraint(expr=model.x >= 8)

306

model.d1.c2 = Constraint(expr=model.y <= 3)

307

308

model.d2 = Disjunct()

309

model.d2.c1 = Constraint(expr=model.x <= 3)

310

model.d2.c2 = Constraint(expr=model.y >= 8)

311

312

model.disjunction = Disjunction(expr=[model.d1, model.d2])

313

model.obj = Objective(expr=model.x + model.y, sense=minimize)

314

315

# Solve with GDPopt

316

solver = SolverFactory('gdpopt')

317

results = solver.solve(model, tee=True, strategy='LOA')

318

```

319

320

### Mixed-Integer Nonlinear Decomposition

321

322

```python

323

from pyomo.environ import *

324

import pyomo.contrib.mindtpy as mindtpy

325

326

# Create MINLP model

327

model = ConcreteModel()

328

model.x = Var(bounds=(1, 10))

329

model.y = Var(domain=Binary)

330

331

model.obj = Objective(expr=model.x**2 + model.y, sense=minimize)

332

model.con1 = Constraint(expr=model.x >= 2*model.y)

333

model.con2 = Constraint(expr=log(model.x) + model.y <= 3)

334

335

# Solve with MindtPy

336

solver = SolverFactory('mindtpy')

337

results = solver.solve(

338

model,

339

strategy='OA', # Outer approximation

340

mip_solver='cplex',

341

nlp_solver='ipopt',

342

tee=True

343

)

344

```

345

346

### Sensitivity Analysis

347

348

```python

349

from pyomo.environ import *

350

from pyomo.contrib.sensitivity_toolbox import sensitivity_calculation

351

352

# Create model

353

model = ConcreteModel()

354

model.x = Var(initialize=1.5)

355

model.y = Var(initialize=1.5)

356

model.p1 = Param(initialize=1.0, mutable=True)

357

model.p2 = Param(initialize=1.0, mutable=True)

358

359

model.obj = Objective(expr=model.x**2 + model.y**2)

360

model.con1 = Constraint(expr=model.x + model.y >= model.p1)

361

model.con2 = Constraint(expr=model.x - model.y <= model.p2)

362

363

# Solve nominal problem

364

solver = SolverFactory('ipopt')

365

solver.solve(model)

366

367

# Perform sensitivity analysis

368

m_sens = sensitivity_calculation(model)

369

sens_results = m_sens.get_dsdp(

370

variables=[model.x, model.y],

371

parameters=[model.p1, model.p2]

372

)

373

374

print("Sensitivity matrix:")

375

print(sens_results)

376

```

377

378

### Parameter Estimation

379

380

```python

381

from pyomo.environ import *

382

import pyomo.contrib.parmest as parmest

383

import pandas as pd

384

385

# Define model function

386

def model_function(data, theta):

387

model = ConcreteModel()

388

model.x = Var(initialize=1)

389

model.theta1 = Param(initialize=theta['theta1'])

390

model.theta2 = Param(initialize=theta['theta2'])

391

392

# Model equations

393

model.response = Expression(

394

expr=model.theta1 * exp(-model.theta2 * data['time'])

395

)

396

397

return model

398

399

# Load experimental data

400

data = pd.DataFrame({

401

'time': [0, 1, 2, 3, 4, 5],

402

'response': [10, 7.4, 5.5, 4.1, 3.0, 2.2]

403

})

404

405

# Create parameter estimation object

406

pest = parmest.Estimator(

407

model_function,

408

data,

409

theta_names=['theta1', 'theta2'],

410

obj_function='SSE' # Sum of squared errors

411

)

412

413

# Estimate parameters

414

theta_est = pest.theta_est()

415

print("Estimated parameters:", theta_est)

416

417

# Bootstrap confidence intervals

418

bootstrap_results = pest.theta_est_bootstrap(100)

419

```

420

421

### Robust Optimization

422

423

```python

424

from pyomo.environ import *

425

import pyomo.contrib.pyros as pyros

426

427

# Create nominal model

428

model = ConcreteModel()

429

model.x = Var(bounds=(0, 10))

430

model.y = Var(bounds=(0, 10))

431

432

# Uncertain parameters

433

model.p1 = Param(initialize=1.0, mutable=True)

434

model.p2 = Param(initialize=2.0, mutable=True)

435

436

model.obj = Objective(expr=model.x + model.y, sense=minimize)

437

model.con1 = Constraint(expr=model.p1 * model.x + model.p2 * model.y >= 5)

438

model.con2 = Constraint(expr=model.x - model.y <= 2)

439

440

# Define uncertainty set

441

uncertainty_set = BoxSet(bounds=[(0.8, 1.2), (1.5, 2.5)])

442

443

# Solve robust optimization problem

444

pyros_solver = pyros.PyROSSolver()

445

results = pyros_solver.solve(

446

model=model,

447

first_stage_variables=[model.x, model.y],

448

second_stage_variables=[],

449

uncertain_params=[model.p1, model.p2],

450

uncertainty_set=uncertainty_set,

451

local_solver=SolverFactory('ipopt'),

452

global_solver=SolverFactory('baron')

453

)

454

```

455

456

### Model Predictive Control

457

458

```python

459

from pyomo.environ import *

460

from pyomo.dae import ContinuousSet, DerivativeVar

461

import pyomo.contrib.mpc as mpc

462

463

# Create dynamic model

464

def create_control_model():

465

model = ConcreteModel()

466

model.time = ContinuousSet(bounds=(0, 1))

467

468

# State variables

469

model.x1 = Var(model.time, bounds=(-10, 10))

470

model.x2 = Var(model.time, bounds=(-10, 10))

471

472

# Control variables

473

model.u = Var(model.time, bounds=(-1, 1))

474

475

# Derivatives

476

model.dx1dt = DerivativeVar(model.x1, wrt=model.time)

477

model.dx2dt = DerivativeVar(model.x2, wrt=model.time)

478

479

# System dynamics

480

model.ode1 = Constraint(

481

model.time,

482

rule=lambda m, t: m.dx1dt[t] == m.x2[t]

483

)

484

model.ode2 = Constraint(

485

model.time,

486

rule=lambda m, t: m.dx2dt[t] == m.u[t]

487

)

488

489

return model

490

491

# Create MPC controller

492

model_template = create_control_model()

493

controller = mpc.ModelPredictiveController(

494

model_template,

495

sample_time=0.1,

496

horizon=10

497

)

498

499

# Simulate closed-loop control

500

current_state = {'x1': 0, 'x2': 0}

501

setpoint = {'x1': 1, 'x2': 0}

502

503

for step in range(50):

504

# Solve MPC optimization

505

control_action = controller.solve_mpc(

506

initial_state=current_state,

507

setpoint=setpoint

508

)

509

510

# Apply first control action

511

u_applied = control_action['u'][0]

512

513

# Simulate system response (simplified)

514

current_state['x1'] += current_state['x2'] * 0.1

515

current_state['x2'] += u_applied * 0.1

516

517

print(f"Step {step}: State = {current_state}, Control = {u_applied}")

518

```

519

520

### Advanced Solver Interface Usage

521

522

```python

523

from pyomo.environ import *

524

import pyomo.contrib.appsi as appsi

525

526

# Create model

527

model = ConcreteModel()

528

model.x = Var(bounds=(0, 10))

529

model.y = Var(bounds=(0, 10))

530

model.obj = Objective(expr=model.x**2 + model.y**2, sense=minimize)

531

model.con = Constraint(expr=model.x + model.y >= 3)

532

533

# Use advanced solver interface

534

solver = appsi.solvers.Ipopt()

535

536

# Configure solver options

537

solver.config.stream_solver = True

538

solver.config.load_solution = True

539

540

# Add model to solver

541

solver.set_instance(model)

542

543

# Solve

544

results = solver.solve()

545

546

# Update model and resolve

547

model.con.set_rhs(5) # Change constraint right-hand side

548

solver.update_config.check_for_new_or_old_constraints = True

549

results = solver.solve() # Warm start from previous solution

550

```