Skip to content

Commit bde8339

Browse files
author
Jason Marechal
committed
docs(api): update API reference and overview documentation
- Added overview section to the API reference - Improved clarity of next steps in strategy guide - Consolidated strategy hierarchy and available combinations - Enhanced links to related documentation for better navigation
1 parent c72bebe commit bde8339

3 files changed

Lines changed: 54 additions & 243 deletions

File tree

docs/api/benders-strategy-api.md

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Benders Strategy Pattern - API Reference
22

3+
**Overview**: See [Architecture Overview](../architecture/benders-strategy-overview.md) for high-level design and diagrams.
4+
35
## Table of Contents
46
1. [Interfaces](#interfaces)
57
2. [Concrete Strategies](#concrete-strategies)
@@ -645,41 +647,7 @@ All methods from `BendersBase` are available in `IBendersCore`, ensuring backwar
645647

646648
## Summary
647649

648-
### Strategy Hierarchy
649-
650-
```
651-
IBendersCore (main interface)
652-
└── BendersCore (orchestrator)
653-
├── IExecutionStrategy
654-
│ ├── SequentialExecutionStrategy
655-
│ └── ParallelMpiExecutionStrategy
656-
├── IBatchingStrategy
657-
│ ├── NoBatchingStrategy
658-
│ └── ByBatchStrategy
659-
└── IOuterLoopStrategy
660-
├── NoOuterLoopStrategy
661-
└── OuterLoopAdapter
662-
```
663-
664-
### Available Combinations
665-
666-
All **8 combinations** are supported:
667-
668-
| Execution | Batching | OuterLoop | When Used |
669-
|-----------|----------|-----------|-----------|
670-
| Sequential | NoBatching | NoOuterLoop | Single process, no options |
671-
| Sequential | NoBatching | OuterLoop | Single process, outer-loop on |
672-
| Sequential | ByBatch | NoOuterLoop | Single process, batching on |
673-
| Sequential | ByBatch | OuterLoop | Single process, batching + outer-loop |
674-
| MPI | NoBatching | NoOuterLoop | Multi-process, no options |
675-
| MPI | NoBatching | OuterLoop | Multi-process, outer-loop on |
676-
| MPI | ByBatch | NoOuterLoop | Multi-process, batching on |
677-
| MPI | ByBatch | OuterLoop | Multi-process, batching + outer-loop |
678-
679-
---
680-
681-
## Next Steps
682-
683-
- Read [Developer Guide](../developer-guide/benders-strategy-guide.md) for usage patterns
684-
- See [Architecture Overview](../architecture/benders-strategy-overview.md) for design details
685-
- Review [Code Navigation](../developer-guide/code-navigation.md) to find code
650+
See [Architecture Overview](../architecture/benders-strategy-overview.md) for:
651+
- Complete strategy hierarchy diagram
652+
- Design principles and benefits
653+
- Available strategy combinations table

docs/architecture/benders-strategy-overview.md

Lines changed: 36 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -68,55 +68,16 @@ This architecture enables **8 different combinations** while maintaining clean s
6868

6969
### Key Abstractions
7070

71-
#### IBendersCore Interface
72-
The main interface for Benders engine operations:
73-
```cpp
74-
class IBendersCore {
75-
public:
76-
virtual void launch() = 0;
77-
virtual void InitializeProblems() = 0;
78-
virtual void set_input_map(const CouplingMap&) = 0;
79-
virtual int MasterRowIndex(const std::string&) const = 0;
80-
virtual LogData GetBestIterationData() const = 0;
81-
virtual WorkerMasterDataVect AllCuts() const = 0;
82-
// ... other methods
83-
};
84-
```
71+
#### Key Strategy Interfaces
8572

86-
#### Strategy Interfaces
87-
88-
**IExecutionStrategy**: Controls how subproblems are solved
89-
```cpp
90-
class IExecutionStrategy {
91-
public:
92-
virtual void Run() = 0;
93-
virtual void InitializeProblems() = 0;
94-
virtual void set_input_map(const CouplingMap&) = 0;
95-
virtual std::string BendersName() const = 0;
96-
// ... other methods
97-
};
98-
```
73+
Three focused interfaces separate concerns:
9974

100-
**IBatchingStrategy**: Controls problem batching
101-
```cpp
102-
class IBatchingStrategy {
103-
public:
104-
virtual void InitializeProblems() = 0;
105-
virtual void UpdateStoppingCriterion() = 0;
106-
virtual bool ShouldRelaxationStop() const = 0;
107-
};
108-
```
75+
- **IBendersCore**: Main interface for Benders engine operations
76+
- **IExecutionStrategy**: Controls how subproblems are solved (Sequential vs. MPI)
77+
- **IBatchingStrategy**: Controls problem batching
78+
- **IOuterLoopStrategy**: Controls outer-loop optimization
10979

110-
**IOuterLoopStrategy**: Controls outer-loop optimization
111-
```cpp
112-
class IOuterLoopStrategy {
113-
public:
114-
virtual void Run(IBendersCore*) = 0;
115-
virtual void init_data() = 0;
116-
virtual bool UpdateMaster(WorkerMasterDataVect&) = 0;
117-
// ... other methods
118-
};
119-
```
80+
For detailed interface signatures and methods, see [API Reference](../../api/benders-strategy-api.md)
12081

12182
## Component Details
12283

@@ -130,135 +91,43 @@ public:
13091
- Delegates operations to appropriate strategy
13192
- Coordinates execution flow
13293

133-
**Location**: `src/cpp/benders/strategy/include/antares-xpansion/benders/strategy/BendersCore.h`
134-
135-
**Example**:
136-
```cpp
137-
class BendersCore : public IBendersCore {
138-
public:
139-
BendersCore(
140-
std::unique_ptr<IExecutionStrategy> exec,
141-
std::unique_ptr<IBatchingStrategy> batch,
142-
std::unique_ptr<IOuterLoopStrategy> outer
143-
);
144-
145-
void launch() override;
146-
// ... other IBendersCore methods
147-
148-
private:
149-
std::unique_ptr<IExecutionStrategy> execution_;
150-
std::unique_ptr<IBatchingStrategy> batching_;
151-
std::unique_ptr<IOuterLoopStrategy> outer_loop_;
152-
};
153-
```
94+
For implementation details and code examples, see [API Reference - BendersCore](../../api/benders-strategy-api.md#orchestrator)
15495

15596
### Execution Strategies
15697

157-
#### SequentialExecutionStrategy
158-
**Wraps**: BendersSequential
159-
**Use Case**: Single-process execution
160-
**Selection**: Automatic when `world->size() == 1`
161-
**Location**: `src/cpp/benders/strategy/include/.../SequentialExecutionStrategy.h`
98+
- **SequentialExecutionStrategy**: Single-process execution
99+
- **ParallelMpiExecutionStrategy**: Multi-process MPI execution
162100

163-
#### ParallelMpiExecutionStrategy
164-
**Wraps**: BendersMPI
165-
**Use Case**: Multi-process MPI execution
166-
**Selection**: Automatic when `world->size() > 1`
167-
**Location**: `src/cpp/benders/strategy/include/.../ParallelMpiExecutionStrategy.h`
101+
Automatically selected based on `world->size()`. Details in [API Reference](../../api/benders-strategy-api.md#concrete-strategies)
168102

169103
### Batching Strategies
170104

171-
#### NoBatchingStrategy
172-
**Behavior**: Passthrough (no batching logic)
173-
**Use Case**: Process all subproblems together
174-
**Selection**: When BENDERSMETHOD doesn't include "BY_BATCH"
175-
**Location**: `src/cpp/benders/strategy/include/.../NoBatchingStrategy.h`
105+
- **NoBatchingStrategy**: Process all subproblems together
106+
- **ByBatchStrategy**: Process subproblems in batches
176107

177-
#### ByBatchStrategy
178-
**Wraps**: BendersByBatch
179-
**Use Case**: Process subproblems in batches
180-
**Selection**: When BENDERSMETHOD includes "BY_BATCH"
181-
**Location**: `src/cpp/benders/strategy/include/.../ByBatchStrategy.h`
108+
Selected based on BENDERSMETHOD enum. See [Developer Guide](../../developer-guide/benders-strategy-guide.md) for usage.
182109

183110
### Outer-Loop Strategies
184111

185-
#### NoOuterLoopStrategy
186-
**Behavior**: Passthrough (no outer-loop optimization)
187-
**Use Case**: Standard Benders without outer loop
188-
**Selection**: When BENDERSMETHOD doesn't include "OUTERLOOP"
189-
**Location**: `src/cpp/benders/strategy/include/.../NoOuterLoopStrategy.h`
112+
- **NoOuterLoopStrategy**: Standard Benders without outer loop
113+
- **OuterLoopAdapter**: Benders with outer-loop optimization
190114

191-
#### OuterLoopAdapter
192-
**Wraps**: Outerloop::OuterLoop
193-
**Use Case**: Benders with outer-loop optimization
194-
**Selection**: When BENDERSMETHOD includes "OUTERLOOP"
195-
**Location**: `src/cpp/benders/strategy/include/.../OuterLoopAdapter.h`
115+
Selected based on BENDERSMETHOD enum. See [API Reference](../../api/benders-strategy-api.md) for details.
196116

197117
## Execution Flow
198118

199-
### Initialization Flow
119+
### Overview
200120

201-
```
202-
BendersFactory::PrepareForExecution()
203-
204-
├─→ Determine BENDERSMETHOD (from options)
205-
206-
├─→ ConfigureBenders()
207-
│ │
208-
│ ├─→ Create ExecutionStrategy
209-
│ │ └─→ world->size() == 1 ? Sequential : MPI
210-
│ │
211-
│ ├─→ Create BatchingStrategy
212-
│ │ └─→ method has BY_BATCH ? ByBatch : NoBatch
213-
│ │
214-
│ ├─→ Create OuterLoopStrategy
215-
│ │ └─→ method has OUTERLOOP ? OuterLoop : None
216-
│ │
217-
│ └─→ Create BendersCore(exec, batch, outer)
218-
219-
└─→ Return BendersEnvironment { benders: IBendersCore* }
220-
```
221-
222-
### Runtime Execution Flow
223-
224-
```
225-
client->launch() // Called on IBendersCore
226-
227-
228-
BendersCore::launch()
229-
230-
├─→ 1. outer_loop_->init_data()
231-
232-
├─→ 2. batching_->InitializeProblems()
233-
234-
├─→ 3. execution_->InitializeProblems()
235-
236-
├─→ 4. if (outer_loop_ != nullptr)
237-
│ │ outer_loop_->Run(this) // Outer loop controls execution
238-
│ │
239-
│ └─→ else
240-
│ execution_->Run() // Direct execution
241-
242-
└─→ 5. batching_->UpdateStoppingCriterion()
243-
```
121+
Execution follows this sequence:
122+
1. **Initialize outer-loop**: Set up data structures
123+
2. **Initialize batching**: Configure batch processing
124+
3. **Initialize execution**: Set up solver strategies
125+
4. **Run**: Execute outer-loop (if enabled) or direct execution
126+
5. **Update stopping criterion**: Check convergence
244127

245-
### Delegation Examples
246-
247-
**Example 1: Get master row index**
248-
```
249-
Client → BendersCore::MasterRowIndex()
250-
251-
└─→ execution_->MasterRowIndex()
252-
253-
└─→ wrapped_benders_->MasterRowIndex()
254-
```
255-
256-
**Example 2: Check if should stop**
257-
```
258-
Client → BendersCore::ShouldRelaxationStop()
259-
260-
└─→ batching_->ShouldRelaxationStop()
261-
```
128+
For detailed flow diagrams and code examples, see:
129+
- [API Reference - Orchestrator](../../api/benders-strategy-api.md#orchestrator)
130+
- [Developer Guide - Using the Strategy Pattern](../../developer-guide/benders-strategy-guide.md#using-the-strategy-pattern)
262131

263132
## Design Principles
264133

@@ -332,9 +201,12 @@ All **8 combinations** are supported:
332201

333202
## Next Steps
334203

335-
For detailed information, see:
336-
- **Developer Guide**: `docs/developer-guide/benders-strategy-guide.md`
337-
- **Code Navigation**: `docs/developer-guide/code-navigation.md`
338-
- **Testing Guide**: `docs/developer-guide/testing-strategy-pattern.md`
339-
- **API Reference**: `docs/api/benders-strategy-api.md`
340-
- **ADR**: `docs/architecture/adr/0001-benders-strategy-pattern.md`
204+
**Start here**: This is a high-level architecture overview.
205+
206+
**For detailed API information**: See [API Reference](../../api/benders-strategy-api.md)
207+
208+
**For practical guidance**: See [Developer Guide](../../developer-guide/benders-strategy-guide.md)
209+
210+
**For code location and navigation**: See [Code Navigation](../../developer-guide/code-navigation.md)
211+
212+
**For architectural decision context**: See [ADR 0001](adr/0001-benders-strategy-pattern.md)

docs/developer-guide/benders-strategy-guide.md

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
4. [Common Patterns](#common-patterns)
88
5. [Best Practices](#best-practices)
99
6. [Troubleshooting](#troubleshooting)
10+
7. [Next Steps](#next-steps)
1011

1112
## Quick Start
1213

@@ -57,45 +58,13 @@ The interface is the same! `IBendersCore` provides all methods from `BendersBase
5758

5859
The factory creates a `BendersCore` with three composed strategies:
5960

60-
```cpp
61-
// Inside BendersFactory::ConfigureBenders()
62-
63-
// 1. Select execution strategy based on MPI world size
64-
if (world_->size() == 1) {
65-
// Single process → Sequential
66-
auto sequential = std::make_unique<BendersSequential>(...);
67-
execution = std::make_unique<SequentialExecutionStrategy>(
68-
std::move(sequential)
69-
);
70-
} else {
71-
// Multiple processes → MPI
72-
auto mpi = std::make_unique<BendersMpi>(...);
73-
execution = std::make_unique<ParallelMpiExecutionStrategy>(
74-
std::move(mpi)
75-
);
76-
}
61+
For details on factory implementation, see [API Reference - Factory](../api/benders-strategy-api.md#factory)
7762

78-
// 2. Select batching strategy based on method
79-
if (method == BENDERS_BY_BATCH || method == BENDERS_BY_BATCH_OUTERLOOP) {
80-
batching = std::make_unique<ByBatchStrategy>(...);
81-
} else {
82-
batching = std::make_unique<NoBatchingStrategy>();
83-
}
84-
85-
// 3. Select outer-loop strategy based on method
86-
if (method == BENDERS_OUTERLOOP || method == BENDERS_BY_BATCH_OUTERLOOP) {
87-
outer_loop = std::make_unique<OuterLoopAdapter>(...);
88-
} else {
89-
outer_loop = std::make_unique<NoOuterLoopStrategy>();
90-
}
91-
92-
// 4. Compose into BendersCore
93-
return std::make_unique<BendersCore>(
94-
std::move(execution),
95-
std::move(batching),
96-
std::move(outer_loop)
97-
);
98-
```
63+
**Key points**:
64+
1. **Execution strategy** is automatically selected based on MPI world size
65+
2. **Batching strategy** is selected based on BENDERSMETHOD enum
66+
3. **Outer-loop strategy** is selected based on BENDERSMETHOD enum
67+
4. All three are composed into BendersCore which orchestrates their execution
9968

10069
### Accessing Strategy Components
10170

@@ -114,6 +83,8 @@ benders->launch();
11483
11584
**Note**: You shouldn't need to access individual strategies directly. `BendersCore` handles all orchestration.
11685
86+
For detailed interface documentation, see [API Reference](../api/benders-strategy-api.md)
87+
11788
## Adding New Strategies
11889
11990
### Example: Adding a GPU Execution Strategy
@@ -530,6 +501,6 @@ Currently, strategies are set at construction. For runtime swapping:
530501

531502
## Next Steps
532503

533-
- Read [Architecture Overview](../architecture/benders-strategy-overview.md)
534-
- Study [Code Navigation Guide](code-navigation.md)
535-
- Check [API Reference](../api/benders-strategy-api.md)
504+
- Read [Architecture Overview](../architecture/benders-strategy-overview.md) for design principles
505+
- Study [Code Navigation Guide](code-navigation.md) to find code in the repository
506+
- Review [API Reference](../api/benders-strategy-api.md) for interface details and method signatures

0 commit comments

Comments
 (0)