-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.rs
More file actions
578 lines (533 loc) · 22.6 KB
/
cli.rs
File metadata and controls
578 lines (533 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser)]
#[command(
name = "pred",
about = "Explore NP-hard problem reductions",
version,
after_help = "\
Typical workflow:
pred create MIS --graph 0-1,1-2,2-3 -o problem.json
pred solve problem.json
pred evaluate problem.json --config 1,0,1,0
Piping (use - to read from stdin):
pred create MIS --graph 0-1,1-2 | pred solve -
pred create MIS --graph 0-1,1-2 | pred evaluate - --config 1,0,1
pred create MIS --graph 0-1,1-2 | pred reduce - --to QUBO
JSON output (any command):
pred list --json # JSON to stdout
pred show MIS --json | jq '.' # pipe to jq
Use `pred <command> --help` for detailed usage of each command.
Use `pred list` to see all available problem types.
Enable tab completion:
eval \"$(pred completions)\" # add to ~/.bashrc or ~/.zshrc"
)]
pub struct Cli {
/// Output file path (implies JSON output)
#[arg(long, short, global = true)]
pub output: Option<PathBuf>,
/// Suppress informational messages on stderr
#[arg(long, short, global = true)]
pub quiet: bool,
/// Output JSON to stdout instead of human-readable text
#[arg(long, global = true)]
pub json: bool,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// List all registered problem types (or reduction rules with --rules)
#[command(after_help = "\
Examples:
pred list # list problem types
pred list --rules # list all reduction rules
pred list -o problems.json # save as JSON")]
List {
/// List reduction rules instead of problem types
#[arg(long)]
rules: bool,
},
/// Show details for a problem type or variant (fields, reductions, complexity)
#[command(after_help = "\
Examples:
pred show MIS # all variants for MIS
pred show MIS/UnitDiskGraph # specific variant
pred show MIS/UnitDiskGraph/i32 # fully qualified variant
pred show KSAT/K3 # KSatisfiability with K=3
Use `pred list` to see all available problem types and variants.")]
Show {
/// Problem name or variant (e.g., MIS, MIS/UnitDiskGraph, KSAT/K3)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
problem: String,
},
/// Explore problems that reduce TO this one (incoming neighbors)
#[command(after_help = "\
Examples:
pred to MIS # what reduces to MIS? (1 hop)
pred to MIS --hops 2 # 2-hop incoming neighbors
pred to MIS -o out.json # save as JSON
Use `pred from <problem>` for outgoing neighbors (what this reduces to).")]
To {
/// Problem name or alias (e.g., MIS, QUBO, MIS/UnitDiskGraph)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
problem: String,
/// Number of hops to explore
#[arg(long, default_value = "1")]
hops: usize,
},
/// Explore problems this reduces to, starting FROM it (outgoing neighbors)
#[command(after_help = "\
Examples:
pred from MIS # what does MIS reduce to? (1 hop)
pred from MIS --hops 2 # 2-hop outgoing neighbors
pred from MIS -o out.json # save as JSON
Use `pred to <problem>` for incoming neighbors (what reduces to this).")]
From {
/// Problem name or alias (e.g., MIS, QUBO, MIS/UnitDiskGraph)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
problem: String,
/// Number of hops to explore
#[arg(long, default_value = "1")]
hops: usize,
},
/// Find the cheapest reduction path between two problems
#[command(after_help = "\
Examples:
pred path MIS QUBO # cheapest path
pred path MIS QUBO --all # all paths
pred path MIS QUBO -o path.json # save for `pred reduce --via`
pred path MIS QUBO --all -o paths/ # save all paths to a folder
pred path MIS QUBO --cost minimize:num_variables
Use `pred list` to see available problems.")]
Path {
/// Source problem (e.g., MIS, MIS/UnitDiskGraph)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
source: String,
/// Target problem (e.g., QUBO)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
target: String,
/// Cost function [default: minimize-steps]
#[arg(long, default_value = "minimize-steps")]
cost: String,
/// Show all paths instead of just the cheapest
#[arg(long)]
all: bool,
/// Maximum paths to return in --all mode
#[arg(long, default_value_t = 20)]
max_paths: usize,
},
/// Export the reduction graph to JSON
#[command(after_help = "\
Examples:
pred export-graph # print to stdout
pred export-graph -o reduction_graph.json # save to file")]
ExportGraph,
/// Create a problem instance and save as JSON
Create(Box<CreateArgs>),
/// Evaluate a configuration against a problem instance JSON file
Evaluate(EvaluateArgs),
/// Reduce a problem instance to a target type
Reduce(ReduceArgs),
/// Inspect a problem JSON or reduction bundle
#[command(after_help = "\
Examples:
pred inspect problem.json
pred inspect bundle.json
pred create MIS --graph 0-1,1-2 | pred inspect -")]
Inspect(InspectArgs),
/// Solve a problem instance
Solve(SolveArgs),
/// Start MCP (Model Context Protocol) server for AI assistant integration
#[cfg(feature = "mcp")]
#[command(after_help = "\
Start a stdio-based MCP server that exposes problem reduction tools
to any MCP-compatible AI assistant.
Configuration:
Claude Code / Claude Desktop (.mcp.json or ~/.claude/mcp.json):
{ \"mcpServers\": { \"problemreductions\": {
\"command\": \"pred\", \"args\": [\"mcp\"] } } }
Cursor (.cursor/mcp.json):
{ \"mcpServers\": { \"problemreductions\": {
\"command\": \"pred\", \"args\": [\"mcp\"] } } }
Windsurf (~/.codeium/windsurf/mcp_config.json):
{ \"mcpServers\": { \"problemreductions\": {
\"command\": \"pred\", \"args\": [\"mcp\"] } } }
OpenCode (opencode.json):
{ \"mcp\": { \"problemreductions\": {
\"type\": \"local\", \"command\": [\"pred\", \"mcp\"] } } }
Test with MCP Inspector:
npx @modelcontextprotocol/inspector pred mcp")]
Mcp,
/// Print shell completions to stdout (auto-detects shell)
#[command(after_help = "\
Setup: add one line to your shell rc file:
# bash (~/.bashrc)
eval \"$(pred completions bash)\"
# zsh (~/.zshrc)
eval \"$(pred completions zsh)\"
# fish (~/.config/fish/config.fish)
pred completions fish | source")]
Completions {
/// Shell type (bash, zsh, fish, etc.). Auto-detected if omitted.
shell: Option<clap_complete::Shell>,
},
}
#[derive(Clone, Debug, ValueEnum)]
pub enum ExampleSide {
Source,
Target,
}
#[derive(clap::Args)]
#[command(after_help = "\
TIP: Run `pred create <PROBLEM>` (no other flags) to see problem-specific help.
Not every flag applies to every problem — the above list shows ALL flags.
Flags by problem type:
MIS, MVC, MaxClique, MinDomSet --graph, --weights
MaxCut, MaxMatching, TSP --graph, --edge-weights
MaximalIS --graph, --weights
SAT, KSAT --num-vars, --clauses [--k]
QUBO --matrix
SpinGlass --graph, --couplings, --fields
KColoring --graph, --k
PartitionIntoTriangles --graph
GraphPartitioning --graph
BoundedComponentSpanningForest --graph, --weights, --k, --bound
UndirectedTwoCommodityIntegralFlow --graph, --capacities, --source-1, --sink-1, --source-2, --sink-2, --requirement-1, --requirement-2
IsomorphicSpanningTree --graph, --tree
LengthBoundedDisjointPaths --graph, --source, --sink, --num-paths-required, --bound
Factoring --target, --m, --n
BinPacking --sizes, --capacity
SubsetSum --sizes, --target
PaintShop --sequence
MaximumSetPacking --sets [--weights]
MinimumSetCovering --universe, --sets [--weights]
X3C (ExactCoverBy3Sets) --universe, --sets (3 elements each)
SetBasis --universe, --sets, --k
TwoDimensionalConsecutiveSets --alphabet-size, --sets
BicliqueCover --left, --right, --biedges, --k
BMF --matrix (0/1), --rank
SteinerTree --graph, --edge-weights, --terminals
CVP --basis, --target-vec [--bounds]
SequencingWithinIntervals --release-times, --deadlines, --lengths
OptimalLinearArrangement --graph, --bound
RuralPostman (RPP) --graph, --edge-weights, --required-edges, --bound
MultipleChoiceBranching --arcs [--weights] --partition --bound [--num-vertices]
SubgraphIsomorphism --graph (host), --pattern (pattern)
LCS --strings
FAS --arcs [--weights] [--num-vertices]
FVS --arcs [--weights] [--num-vertices]
FlowShopScheduling --task-lengths, --deadline [--num-processors]
MinimumTardinessSequencing --n, --deadlines [--precedence-pairs]
SCS --strings, --bound [--alphabet-size]
D2CIF --arcs, --capacities, --source-1, --sink-1, --source-2, --sink-2, --requirement-1, --requirement-2
ILP, CircuitSAT (via reduction only)
Geometry graph variants (use slash notation, e.g., MIS/KingsSubgraph):
KingsSubgraph, TriangularSubgraph --positions (integer x,y pairs)
UnitDiskGraph --positions (float x,y pairs) [--radius]
Random generation:
--random --num-vertices N [--edge-prob 0.5] [--seed 42]
Examples:
pred create --example MIS/SimpleGraph/i32
pred create --example MVC/SimpleGraph/i32 --to MIS/SimpleGraph/i32
pred create --example MVC/SimpleGraph/i32 --to MIS/SimpleGraph/i32 --example-side target
pred create MIS --graph 0-1,1-2,2-3 --weights 1,1,1
pred create SAT --num-vars 3 --clauses \"1,2;-1,3\"
pred create QUBO --matrix \"1,0.5;0.5,2\"
pred create MultipleChoiceBranching/i32 --arcs \"0>1,0>2,1>3,2>3,1>4,3>5,4>5,2>4\" --weights 3,2,4,1,2,3,1,3 --partition \"0,1;2,3;4,7;5,6\" --bound 10
pred create MIS/KingsSubgraph --positions \"0,0;1,0;1,1;0,1\"
pred create MIS/UnitDiskGraph --positions \"0,0;1,0;0.5,0.8\" --radius 1.5
pred create MIS --random --num-vertices 10 --edge-prob 0.3
pred create FVS --arcs \"0>1,1>2,2>0\" --weights 1,1,1
pred create UndirectedTwoCommodityIntegralFlow --graph 0-2,1-2,2-3 --capacities 1,1,2 --source-1 0 --sink-1 3 --source-2 1 --sink-2 3 --requirement-1 1 --requirement-2 1
pred create X3C --universe 9 --sets \"0,1,2;0,2,4;3,4,5;3,5,7;6,7,8;1,4,6;2,5,8\"
pred create SetBasis --universe 4 --sets \"0,1;1,2;0,2;0,1,2\" --k 3
pred create TwoDimensionalConsecutiveSets --alphabet-size 6 --sets \"0,1,2;3,4,5;1,3;2,4;0,5\"")]
pub struct CreateArgs {
/// Problem type (e.g., MIS, QUBO, SAT). Omit when using --example.
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
pub problem: Option<String>,
/// Build a problem from the canonical example database using a structural problem spec.
#[arg(long, value_parser = crate::problem_name::ProblemNameParser)]
pub example: Option<String>,
/// Target problem spec for canonical rule example lookup.
#[arg(long = "to", value_parser = crate::problem_name::ProblemNameParser)]
pub example_target: Option<String>,
/// Which side of a rule example to emit [default: source].
#[arg(long, value_enum, default_value = "source")]
pub example_side: ExampleSide,
/// Graph edge list (e.g., 0-1,1-2,2-3)
#[arg(long)]
pub graph: Option<String>,
/// Vertex weights (e.g., 1,1,1,1) [default: all 1s]
#[arg(long)]
pub weights: Option<String>,
/// Edge weights (e.g., 2,3,1) [default: all 1s]
#[arg(long)]
pub edge_weights: Option<String>,
/// Edge capacities for multicommodity flow problems (e.g., 1,1,2)
#[arg(long)]
pub capacities: Option<String>,
/// Source vertex for path-based graph problems
#[arg(long)]
pub source: Option<usize>,
/// Sink vertex for path-based graph problems
#[arg(long)]
pub sink: Option<usize>,
/// Required number of paths for LengthBoundedDisjointPaths
#[arg(long)]
pub num_paths_required: Option<usize>,
/// Pairwise couplings J_ij for SpinGlass (e.g., 1,-1,1) [default: all 1s]
#[arg(long)]
pub couplings: Option<String>,
/// On-site fields h_i for SpinGlass (e.g., 0,0,1) [default: all 0s]
#[arg(long)]
pub fields: Option<String>,
/// Clauses for SAT problems (semicolon-separated, e.g., "1,2;-1,3")
#[arg(long)]
pub clauses: Option<String>,
/// Number of variables (for SAT/KSAT)
#[arg(long)]
pub num_vars: Option<usize>,
/// Matrix for QUBO (semicolon-separated rows, e.g., "1,0.5;0.5,2")
#[arg(long)]
pub matrix: Option<String>,
/// Number of colors for KColoring
#[arg(long)]
pub k: Option<usize>,
/// Generate a random instance (graph-based problems only)
#[arg(long)]
pub random: bool,
/// Number of vertices for random graph generation
#[arg(long)]
pub num_vertices: Option<usize>,
/// Edge probability for random graph generation (0.0 to 1.0) [default: 0.5]
#[arg(long)]
pub edge_prob: Option<f64>,
/// Random seed for reproducibility
#[arg(long)]
pub seed: Option<u64>,
/// Target value (for Factoring and SubsetSum)
#[arg(long)]
pub target: Option<String>,
/// Bits for first factor (for Factoring)
#[arg(long)]
pub m: Option<usize>,
/// Bits for second factor (for Factoring)
#[arg(long)]
pub n: Option<usize>,
/// Vertex positions for geometry-based graphs (semicolon-separated x,y pairs, e.g., "0,0;1,0;1,1")
#[arg(long)]
pub positions: Option<String>,
/// Radius for UnitDiskGraph [default: 1.0]
#[arg(long)]
pub radius: Option<f64>,
/// Source vertex s_1 for commodity 1
#[arg(long)]
pub source_1: Option<usize>,
/// Sink vertex t_1 for commodity 1
#[arg(long)]
pub sink_1: Option<usize>,
/// Source vertex s_2 for commodity 2
#[arg(long)]
pub source_2: Option<usize>,
/// Sink vertex t_2 for commodity 2
#[arg(long)]
pub sink_2: Option<usize>,
/// Required flow R_1 for commodity 1
#[arg(long)]
pub requirement_1: Option<u64>,
/// Required flow R_2 for commodity 2
#[arg(long)]
pub requirement_2: Option<u64>,
/// Item sizes for BinPacking (comma-separated, e.g., "3,3,2,2")
#[arg(long)]
pub sizes: Option<String>,
/// Bin capacity for BinPacking
#[arg(long)]
pub capacity: Option<String>,
/// Car paint sequence for PaintShop (comma-separated, each label appears exactly twice, e.g., "a,b,a,c,c,b")
#[arg(long)]
pub sequence: Option<String>,
/// Sets for SetPacking/SetCovering (semicolon-separated, e.g., "0,1;1,2;0,2")
#[arg(long)]
pub sets: Option<String>,
/// Partition groups for arc-index partitions (semicolon-separated, e.g., "0,1;2,3")
#[arg(long)]
pub partition: Option<String>,
/// Universe size for MinimumSetCovering
#[arg(long)]
pub universe: Option<usize>,
/// Bipartite graph edges for BicliqueCover (e.g., "0-0,0-1,1-2" for left-right pairs)
#[arg(long)]
pub biedges: Option<String>,
/// Left partition size for BicliqueCover
#[arg(long)]
pub left: Option<usize>,
/// Right partition size for BicliqueCover
#[arg(long)]
pub right: Option<usize>,
/// Rank for BMF
#[arg(long)]
pub rank: Option<usize>,
/// Lattice basis for CVP (semicolon-separated column vectors, e.g., "1,0;0,1")
#[arg(long)]
pub basis: Option<String>,
/// Target vector for CVP (comma-separated, e.g., "0.5,0.5")
#[arg(long)]
pub target_vec: Option<String>,
/// Variable bounds for CVP as "lower,upper" (e.g., "-10,10") [default: -10,10]
#[arg(long, allow_hyphen_values = true)]
pub bounds: Option<String>,
/// Release times for SequencingWithinIntervals (comma-separated, e.g., "0,0,5")
#[arg(long)]
pub release_times: Option<String>,
/// Processing lengths for SequencingWithinIntervals (comma-separated, e.g., "3,1,1")
#[arg(long)]
pub lengths: Option<String>,
/// Terminal vertices for SteinerTree (comma-separated indices, e.g., "0,2,4")
#[arg(long)]
pub terminals: Option<String>,
/// Tree edge list for IsomorphicSpanningTree (e.g., 0-1,1-2,2-3)
#[arg(long)]
pub tree: Option<String>,
/// Required edge indices for RuralPostman (comma-separated, e.g., "0,2,4")
#[arg(long)]
pub required_edges: Option<String>,
/// Upper bound or length bound (for BoundedComponentSpanningForest, LengthBoundedDisjointPaths, MultipleChoiceBranching, OptimalLinearArrangement, RuralPostman, or SCS)
#[arg(long, allow_hyphen_values = true)]
pub bound: Option<i64>,
/// Pattern graph edge list for SubgraphIsomorphism (e.g., 0-1,1-2,2-0)
#[arg(long)]
pub pattern: Option<String>,
/// Input strings for LCS (e.g., "ABAC;BACA") or SCS (e.g., "0,1,2;1,2,0")
#[arg(long)]
pub strings: Option<String>,
/// Directed arcs for directed graph problems (e.g., 0>1,1>2,2>0)
#[arg(long)]
pub arcs: Option<String>,
/// Deadlines for MinimumTardinessSequencing (comma-separated, e.g., "5,5,5,3,3")
#[arg(long)]
pub deadlines: Option<String>,
/// Precedence pairs for MinimumTardinessSequencing (e.g., "0>3,1>3,1>4,2>4")
#[arg(long)]
pub precedence_pairs: Option<String>,
/// Task lengths for FlowShopScheduling (semicolon-separated rows: "3,4,2;2,3,5;4,1,3")
#[arg(long)]
pub task_lengths: Option<String>,
/// Deadline for FlowShopScheduling
#[arg(long)]
pub deadline: Option<u64>,
/// Number of processors/machines for FlowShopScheduling
#[arg(long)]
pub num_processors: Option<usize>,
/// Alphabet size for SCS (optional) or TwoDimensionalConsecutiveSets
#[arg(long)]
pub alphabet_size: Option<usize>,
}
#[derive(clap::Args)]
#[command(after_help = "\
Examples:
pred solve problem.json # ILP solver (default, auto-reduces to ILP)
pred solve problem.json --solver brute-force # brute-force (exhaustive search)
pred solve reduced.json # solve a reduction bundle
pred solve reduced.json -o solution.json # save result to file
pred create MIS --graph 0-1,1-2 | pred solve - # read from stdin
pred create TwoDimensionalConsecutiveSets --alphabet-size 6 --sets \"0,1,2;3,4,5;1,3;2,4;0,5\" | pred solve - --solver brute-force
pred solve problem.json --timeout 10 # abort after 10 seconds
Typical workflow:
pred create MIS --graph 0-1,1-2,2-3 -o problem.json
pred solve problem.json
Solve via explicit reduction:
pred reduce problem.json --to QUBO -o reduced.json
pred solve reduced.json
Input: a problem JSON from `pred create`, or a reduction bundle from `pred reduce`.
When given a bundle, the target is solved and the solution is mapped back to the source.
The ILP solver auto-reduces non-ILP problems before solving.
ILP backend (default: HiGHS). To use a different backend:
cargo install problemreductions-cli --features coin-cbc
cargo install problemreductions-cli --features scip
cargo install problemreductions-cli --no-default-features --features clarabel")]
pub struct SolveArgs {
/// Problem JSON file (from `pred create`) or reduction bundle (from `pred reduce`). Use - for stdin.
pub input: PathBuf,
/// Solver: ilp (default) or brute-force
#[arg(long, default_value = "ilp")]
pub solver: String,
/// Timeout in seconds (0 = no limit)
#[arg(long, default_value = "0")]
pub timeout: u64,
}
#[derive(clap::Args)]
#[command(after_help = "\
Examples:
pred reduce problem.json --to QUBO -o reduced.json
pred reduce problem.json --to ILP -o reduced.json
pred reduce problem.json --via path.json -o reduced.json
pred create MIS --graph 0-1,1-2 | pred reduce - --to QUBO # read from stdin
Input: a problem JSON from `pred create`. Use - to read from stdin.
The --via path file is from `pred path <SRC> <DST> -o path.json`.
When --via is given, --to is inferred from the path file.
Output is a reduction bundle with source, target, and path.
Use `pred solve reduced.json` to solve and map the solution back.")]
pub struct ReduceArgs {
/// Problem JSON file (from `pred create`). Use - for stdin.
pub input: PathBuf,
/// Target problem type (e.g., QUBO, SpinGlass). Inferred from --via if omitted.
#[arg(long, value_parser = crate::problem_name::ProblemNameParser)]
pub to: Option<String>,
/// Reduction route file (from `pred path ... -o`)
#[arg(long)]
pub via: Option<PathBuf>,
}
#[derive(clap::Args)]
pub struct InspectArgs {
/// Problem JSON file or reduction bundle. Use - for stdin.
pub input: PathBuf,
}
#[derive(clap::Args)]
#[command(after_help = "\
Examples:
pred evaluate problem.json --config 1,0,1,0
pred evaluate problem.json --config 1,0,1,0 -o result.json
pred create MIS --graph 0-1,1-2 | pred evaluate - --config 1,0,1 # read from stdin
Input: a problem JSON from `pred create`. Use - to read from stdin.")]
pub struct EvaluateArgs {
/// Problem JSON file (from `pred create`). Use - for stdin.
pub input: PathBuf,
/// Configuration to evaluate (comma-separated, e.g., 1,0,1,0)
#[arg(long)]
pub config: String,
}
/// Print the after_help text for a subcommand on parse error.
///
/// Only matches the first line of the error message. Without this,
/// bare `pred` (no subcommand) would match "pred solve" in the
/// top-level workflow examples and incorrectly append the solve
/// subcommand's help text.
pub fn print_subcommand_help_hint(error_msg: &str) {
let first_line = error_msg.lines().next().unwrap_or("");
let subcmds = [
("pred solve", "solve"),
("pred reduce", "reduce"),
("pred create", "create"),
("pred evaluate", "evaluate"),
("pred inspect", "inspect"),
("pred path", "path"),
("pred show", "show"),
("pred to", "to"),
("pred from", "from"),
("pred export-graph", "export-graph"),
];
let cmd = Cli::command();
for (pattern, name) in subcmds {
if first_line.contains(pattern) {
if let Some(sub) = cmd.find_subcommand(name) {
if let Some(help) = sub.get_after_help() {
eprintln!("\n{help}");
}
}
return;
}
}
}