You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int status = solve_race_schedule(raceDataJson, options, &resultJson);
37
+
38
+
// Always free the result
39
+
free_solver_result(resultJson);
57
40
```
58
41
42
+
For a complete working example, see [`cmd/solver/cli.cpp`](./cmd/solver/cli.cpp).
43
+
44
+
#### Solver vs. Diagnostic Mode
45
+
46
+
- **`solve_race_schedule()`**: Finds an optimal schedule satisfying all constraints. Returns an error if no feasible solution exists.
47
+
48
+
- **`diagnose_race_schedule()`**: When the solver fails, this runs a relaxed model to identify which constraints are causing the infeasibility.
49
+
50
+
#### Controlling Solve Time
51
+
52
+
The solver can take a very long time (or never complete) for complex schedules if not properly constrained. Use `timeLimit` and `optimalityGap` to prevent excessive runtimes:
- **`timeLimit`**: Maximum seconds the solver will run before returning the best solution found. This is a hard stop.
57
+
58
+
- **`optimalityGap`**: Allows the solver to stop early when it finds a "good enough" solution within this percentage of the theoretical optimum. For example, `0.2` means the solver stops once it finds a solution within 20% of optimal.
59
+
60
+
**Why a small optimality gap is expensive and unnecessary:**
61
+
62
+
Mixed Integer Programming problems like race scheduling are NP-hard. The solver may find a good feasible solution quickly (in seconds), but proving that solution is within 1% of optimal can take exponentially longer—hours or even days. For practical scheduling:
63
+
64
+
- A 20% gap solution is typically excellent and solves in seconds
65
+
- A 5% gap might take 10-100x longer with minimal practical benefit
66
+
- A 1% gap can be prohibitively expensive, often timing out
67
+
- The "optimal" schedule and a 20% suboptimal schedule are often nearly identical in practice—swapping equivalent drivers or spotters
68
+
69
+
The solver prioritizes hard constraints (rest times, fuel, availability) first. The optimality gap only affects soft preferences like minimizing consecutive stints. A 20% gap on these preferences is imperceptible in real-world use.
70
+
59
71
-----
60
72
61
73
### Input JSON Specification
@@ -183,6 +195,7 @@ The function returns a JSON string containing the solution or error details.
183
195
}
184
196
```
185
197
198
+
186
199
---
187
200
188
201
_Created by popmonkey, Gemini 2.5, Gemini 3.0, and ChatGPT 5.1_
Copy file name to clipboardExpand all lines: TOOLS.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,20 +18,15 @@ brew tap popmonkey/jres_solver
18
18
brew install jres_solver
19
19
```
20
20
21
-
### Windows Specific Requirement
22
-
23
-
On Windows, the `jres_solver` application is built as a thin executable that relies on a shared library. You must ensure the following DLL is present in the same directory as the executable (or in your system `%PATH%`):
24
-
25
-
***`jres_solver.dll`**
26
-
27
-
The `jres_formatter` tool is statically linked and does not require this DLL.
28
-
29
21
---
30
22
31
23
## Solver (`jres_solver`)
32
24
33
25
The **Solver** is the core engine. It accepts raw race data (track info, driver constraints, car specs) and calculates the optimal driver schedule.
34
26
27
+
> [!TIP]
28
+
> See the [README](./README.md#controlling-solve-time) for guidance on controlling solve time and understanding the difference between [Solver vs. Diagnostic Mode](./README.md#solver-vs-diagnostic-mode).
29
+
35
30
### Usage
36
31
37
32
```sh
@@ -101,11 +96,18 @@ If a schedule fails to solve, run with `-d` to get a plain English explanation o
101
96
./jres_solver -i race_config.json --diagnose
102
97
```
103
98
104
-
**Advanced Optimization:**
105
-
Run for up to 5 minutes (`300s`), use `integrated` spotter logic, and allow a 1% margin of error for faster results.
99
+
**With Spotter Scheduling:**
100
+
Use `integrated` spotter logic with a reasonable optimality gap for faster results.
0 commit comments