Skip to content

Commit a7e04be

Browse files
authored
Defaults for optimal gap and time limit (#29)
* Update documentation for improved clarity and structure; add formatter CLI details and usage examples Fixes #27 * Refactor solver options: update default values for time limit and optimality gap; remove unused quiet flag from context Fixes #18
1 parent e31bc44 commit a7e04be

9 files changed

Lines changed: 6 additions & 28 deletions

File tree

cmd/solver/cli.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ int main(int argc, char **argv)
3232
options.add_options()
3333
("i,input", "Path to the race data .json file. Reads from stdin if not provided.", cxxopts::value<std::string>())
3434
("o,output", "Optional. Path to save the schedule as a JSON file.", cxxopts::value<std::string>())
35-
("t,time-limit", "Maximum time in seconds to let the solver run.", cxxopts::value<int>()->default_value("30"))
35+
("t,time-limit", "Maximum time in seconds to let the solver run.", cxxopts::value<int>()->default_value("5"))
3636
("q,quiet", "Suppress INFO logs and final schedule print-out.", cxxopts::value<bool>()->default_value("false"))
3737
("s,spotter-mode", "Method for scheduling spotters (none, integrated, sequential).", cxxopts::value<std::string>()->default_value("none"))
3838
("allow-no-spotter", "Allow stints to have no spotter assigned.", cxxopts::value<bool>()->default_value("false"))
39-
("g,optimality-gap", "Solver stops when the gap to optimal is less than this (e.g., 0.01 for 1%).", cxxopts::value<double>()->default_value("0.0"))
39+
("g,optimality-gap", "Solver stops when the gap to optimal is less than this (e.g., 0.2 for 20%).", cxxopts::value<double>()->default_value("0.2"))
4040
("d,diagnose", "Run diagnostics to explain why a schedule is infeasible.", cxxopts::value<bool>()->default_value("false"))
4141
("v,version", "Print version information and exit.")
4242
("h,help", "Print usage.");
@@ -97,7 +97,6 @@ int main(int argc, char **argv)
9797

9898
// Build Solver Options Struct
9999
JresSolverOptions solverOptions;
100-
solverOptions.quiet = quiet;
101100
solverOptions.timeLimit = result["time-limit"].as<int>();
102101

103102
// --- Translate spotter-mode string to enum ---

include/jres_solver/jres_solver.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ enum JresSpotterMode {
4949
* @brief Options for the race schedule solver.
5050
*/
5151
struct JresSolverOptions {
52-
int timeLimit; // Maximum time in seconds to let the solver run
53-
JresSpotterMode spotterMode; // Type of spotter scheduling to use
54-
bool allowNoSpotter; // Allow stints to have no spotter assigned
55-
double optimalityGap; // e.g., 0.01 for 1%
56-
bool quiet; // Suppress console logging from the library
52+
int timeLimit = 5; // Maximum time in seconds to let the solver run (default: 5)
53+
JresSpotterMode spotterMode = JRES_SPOTTER_MODE_NONE; // Type of spotter scheduling to use
54+
bool allowNoSpotter = false; // Allow stints to have no spotter assigned
55+
double optimalityGap = 0.2; // Optimality gap (default: 0.2 = 20%)
5756
};
5857

5958
/**

src/jres_solver.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ int solve_race_schedule(const char* raceDataJson,
3939
try {
4040
json rawJsonData = json::parse(raceDataJson);
4141
SolverContext ctx;
42-
ctx.quiet = options.quiet;
4342
ctx.timeLimit = options.timeLimit;
4443
ctx.spotterMode = translate_spotter_mode(options.spotterMode);
4544
ctx.allowNoSpotter = options.allowNoSpotter;
@@ -69,7 +68,6 @@ int diagnose_race_schedule(const char* raceDataJson,
6968
try {
7069
json rawJsonData = json::parse(raceDataJson);
7170
SolverContext ctx;
72-
ctx.quiet = options.quiet;
7371
ctx.timeLimit = options.timeLimit;
7472
ctx.spotterMode = translate_spotter_mode(options.spotterMode);
7573
ctx.allowNoSpotter = options.allowNoSpotter;

src/jres_solver_types.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void to_json(json &j, const SolverContext &ctx)
5959
// We intentionally do NOT include 'raceData' here to avoid
6060
// duplication in the final output, as this is used for the "metadata" block.
6161
j = json{
62-
{"quiet", ctx.quiet},
6362
{"timeLimit", ctx.timeLimit},
6463
{"spotterMode", ctx.spotterMode}, // Serializes to string via enum mapping
6564
{"allowNoSpotter", ctx.allowNoSpotter},

src/jres_solver_types.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ NLOHMANN_JSON_SERIALIZE_ENUM( SpotterMode, {
5656

5757
struct SolverContext
5858
{
59-
bool quiet;
6059
int timeLimit;
6160
SpotterMode spotterMode;
6261
bool allowNoSpotter;

test/test_constraints.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ TEST(ConstraintTest, InfeasibleModel) {
2929
options.spotterMode = JRES_SPOTTER_MODE_NONE;
3030
options.allowNoSpotter = false;
3131
options.optimalityGap = 0.0;
32-
options.quiet = true;
3332

3433
char* resultJsonCStr = nullptr;
3534
int resultCode = solve_race_schedule(INFEASIBLE_JSON, options, &resultJsonCStr);
@@ -76,7 +75,6 @@ TEST(ConstraintTest, PreferredSlot) {
7675
options.spotterMode = JRES_SPOTTER_MODE_NONE;
7776
options.allowNoSpotter = false;
7877
options.optimalityGap = 0.0;
79-
options.quiet = true;
8078

8179
char* resultJsonCStr = nullptr;
8280
int resultCode = solve_race_schedule(PREFERRED_SLOT_JSON, options, &resultJsonCStr);

test/test_diagnosis.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace {
2828
JresSolverOptions options;
2929
options.timeLimit = 10;
3030
options.spotterMode = JRES_SPOTTER_MODE_NONE;
31-
options.quiet = true;
3231

3332
char* resultJsonCStr = nullptr;
3433
int resultCode = diagnose_race_schedule(UNAVAILABLE_JSON, options, &resultJsonCStr);
@@ -80,7 +79,6 @@ namespace {
8079
JresSolverOptions options;
8180
options.timeLimit = 10;
8281
options.spotterMode = JRES_SPOTTER_MODE_NONE;
83-
options.quiet = true;
8482

8583
char* resultJsonCStr = nullptr;
8684
int resultCode = diagnose_race_schedule(MAX_CONSECUTIVE_JSON, options, &resultJsonCStr);

test/test_errors.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace {
2222
JresSolverOptions options;
2323
options.timeLimit = 10;
2424
options.spotterMode = JRES_SPOTTER_MODE_NONE;
25-
options.quiet = true;
2625

2726
char* resultJsonCStr = nullptr;
2827
int resultCode = solve_race_schedule(MALFORMED_JSON, options, &resultJsonCStr);
@@ -62,7 +61,6 @@ TEST(ErrorTest, MissingSchemaKey) {
6261
JresSolverOptions options;
6362
options.timeLimit = 10;
6463
options.spotterMode = JRES_SPOTTER_MODE_NONE;
65-
options.quiet = true;
6664

6765
char* resultJsonCStr = nullptr;
6866
int resultCode = solve_race_schedule(MISSING_KEY_JSON, options, &resultJsonCStr);
@@ -100,7 +98,6 @@ TEST(ErrorTest, NoDrivers) {
10098
JresSolverOptions options;
10199
options.timeLimit = 10;
102100
options.spotterMode = JRES_SPOTTER_MODE_NONE;
103-
options.quiet = true;
104101

105102
char* resultJsonCStr = nullptr;
106103
int resultCode = solve_race_schedule(NO_DRIVERS_JSON, options, &resultJsonCStr);
@@ -133,7 +130,6 @@ TEST(ErrorTest, NoSpottersRequired) {
133130
options.timeLimit = 10;
134131
options.spotterMode = JRES_SPOTTER_MODE_INTEGRATED;
135132
options.allowNoSpotter = false; // <-- This makes it an error
136-
options.quiet = true;
137133

138134
char* resultJsonCStr = nullptr;
139135
int resultCode = solve_race_schedule(NO_SPOTTERS_JSON, options, &resultJsonCStr);
@@ -165,7 +161,6 @@ TEST(ErrorTest, ZeroDuration) {
165161
JresSolverOptions options;
166162
options.timeLimit = 10;
167163
options.spotterMode = JRES_SPOTTER_MODE_NONE;
168-
options.quiet = true;
169164

170165
char* resultJsonCStr = nullptr;
171166
int resultCode = solve_race_schedule(ZERO_DURATION_JSON, options, &resultJsonCStr);

test/test_spotter_modes.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace {
4444
options.spotterMode = JRES_SPOTTER_MODE_INTEGRATED;
4545
options.allowNoSpotter = false;
4646
options.optimalityGap = 0.0;
47-
options.quiet = true;
4847

4948
char* resultJsonCStr = nullptr;
5049
int resultCode = solve_race_schedule(SOLVABLE_JSON, options, &resultJsonCStr);
@@ -84,7 +83,6 @@ namespace {
8483
options.spotterMode = JRES_SPOTTER_MODE_NONE;
8584
options.allowNoSpotter = false;
8685
options.optimalityGap = 0.0;
87-
options.quiet = true;
8886

8987
char* resultJsonCStr = nullptr;
9088
int resultCode = solve_race_schedule(SPOTTER_NONE_JSON, options, &resultJsonCStr);
@@ -123,7 +121,6 @@ namespace {
123121
options.spotterMode = JRES_SPOTTER_MODE_INTEGRATED;
124122
options.allowNoSpotter = false; // <-- This forces the conflict
125123
options.optimalityGap = 0.0;
126-
options.quiet = true;
127124

128125
char* resultJsonCStr = nullptr;
129126
int resultCode = solve_race_schedule(CONFLICT_INTEGRATED_JSON, options, &resultJsonCStr);
@@ -162,7 +159,6 @@ namespace {
162159
options.spotterMode = JRES_SPOTTER_MODE_SEQUENTIAL;
163160
options.allowNoSpotter = false;
164161
options.optimalityGap = 0.0;
165-
options.quiet = true;
166162

167163
char* resultJsonCStr = nullptr;
168164
int resultCode = solve_race_schedule(CONFLICT_SEQUENTIAL_JSON, options, &resultJsonCStr);
@@ -205,7 +201,6 @@ namespace {
205201
options.spotterMode = JRES_SPOTTER_MODE_INTEGRATED;
206202
options.allowNoSpotter = true; // <-- Key for this test
207203
options.optimalityGap = 0.0;
208-
options.quiet = true;
209204

210205
char* resultJsonCStr = nullptr;
211206
int resultCode = solve_race_schedule(NO_SPOTTERS_JSON, options, &resultJsonCStr);
@@ -234,7 +229,6 @@ namespace {
234229
options.spotterMode = JRES_SPOTTER_MODE_SEQUENTIAL;
235230
options.allowNoSpotter = true; // <-- Key for this test
236231
options.optimalityGap = 0.0;
237-
options.quiet = true;
238232

239233
char* resultJsonCStr = nullptr;
240234
int resultCode = solve_race_schedule(NO_SPOTTERS_JSON, options, &resultJsonCStr);
@@ -280,7 +274,6 @@ TEST(SpotterModeTest, SequentialInfeasibleSpotter) {
280274
options.spotterMode = JRES_SPOTTER_MODE_SEQUENTIAL;
281275
options.allowNoSpotter = false; // <-- Key for this test
282276
options.optimalityGap = 0.0;
283-
options.quiet = true;
284277

285278
char* resultJsonCStr = nullptr;
286279
int resultCode = solve_race_schedule(SEQ_INFEASIBLE_JSON, options, &resultJsonCStr);

0 commit comments

Comments
 (0)