@@ -27,7 +27,42 @@ zelen = "0.1"
2727
2828## Quick Start
2929
30- ### From FlatZinc String
30+ ### Recommended API: FlatZincSolver
31+
32+ The easiest way to use Zelen is with the ` FlatZincSolver ` - it provides automatic FlatZinc-compliant output:
33+
34+ ``` rust
35+ use zelen :: prelude :: * ;
36+
37+ let fzn = r # "
38+ var 1..10: x;
39+ var 1..10: y;
40+ constraint int_eq(x, 5);
41+ constraint int_plus(x, y, 12);
42+ solve satisfy;
43+ " # ;
44+
45+ let mut solver = FlatZincSolver :: new ();
46+ solver . load_str (fzn )? ;
47+ solver . solve ()? ;
48+
49+ // Automatic FlatZinc-compliant output with statistics
50+ print! (" {}" , solver . to_flatzinc ());
51+ // Outputs:
52+ // x = 5;
53+ // y = 7;
54+ // ----------
55+ // ==========
56+ // %%%mzn-stat: solutions=1
57+ // %%%mzn-stat: nodes=0
58+ // %%%mzn-stat: propagations=0
59+ // %%%mzn-stat: solveTime=0.001
60+ // %%%mzn-stat-end
61+ ```
62+
63+ ### Low-Level API: Direct Model Integration
64+
65+ For more control, use the Model integration API:
3166
3267``` rust
3368use zelen :: prelude :: * ;
@@ -103,54 +138,59 @@ if let Ok(solution) = model.solve() {
103138}
104139```
105140
106- ### FlatZinc-Compliant Output
141+ ### Configurable Output and Statistics
107142
108- Zelen provides a formatter to output solutions according to the FlatZinc specification :
143+ Control statistics and solution enumeration :
109144
110145``` rust
111146use zelen :: prelude :: * ;
112- use zelen :: output :: format_solution;
113- use std :: collections :: HashMap ;
114147
115- let fzn = r # "
116- var 1..10: x;
117- var 1..10: y;
118- constraint int_eq(x, 5);
119- constraint int_eq(y, 3);
120- solve satisfy;
121- " # ;
148+ let fzn = " var 1..10: x; solve satisfy;" ;
122149
123- let mut model = Model :: default ();
124- model . from_flatzinc_str (fzn )? ;
150+ // Configure solver options
151+ let mut solver = FlatZincSolver :: new ();
152+ solver . with_statistics (true ); // Enable/disable statistics
153+ solver . max_solutions (3 ); // Find up to 3 solutions
154+ solver . find_all_solutions (); // Find all solutions
125155
126- match model . solve () {
127- Ok (solution ) => {
128- // Get variable names from the parser (you'd track these during parsing)
129- let var_names = HashMap :: from ([
130- (x_var_id , " x" . to_string ()),
131- (y_var_id , " y" . to_string ()),
132- ]);
133-
134- // Format according to FlatZinc spec
135- let output = format_solution (& solution , & var_names );
136- print! (" {}" , output );
137- // Outputs:
138- // x = 5;
139- // y = 3;
140- // ----------
141- }
142- Err (_ ) => {
143- println! (" {}" , zelen :: output :: format_no_solution ());
144- // Outputs: =====UNSATISFIABLE=====
145- }
146- }
156+ solver . load_str (fzn )? ;
157+ solver . solve ()? ;
158+
159+ // Get formatted output
160+ let output = solver . to_flatzinc (); // Returns String
161+ solver . print_flatzinc (); // Prints directly
162+
163+ // Access solutions programmatically
164+ let count = solver . solution_count ();
165+ let solution = solver . get_solution (0 );
166+ ```
167+
168+ ### FlatZinc Specification Compliance
169+
170+ Zelen follows the [ FlatZinc specification] ( https://docs.minizinc.dev/en/stable/fzn-spec.html#output ) exactly:
171+
172+ ** Output Format:**
173+ - Variable assignments: ` varname = value; `
174+ - Solution separator: ` ---------- `
175+ - Search complete: ` ========== `
176+ - Unsatisfiable: ` =====UNSATISFIABLE===== `
177+
178+ ** Statistics Format** (optional, configurable):
179+ ```
180+ %%%mzn-stat: solutions=1
181+ %%%mzn-stat: nodes=10
182+ %%%mzn-stat: failures=0
183+ %%%mzn-stat: propagations=21
184+ %%%mzn-stat: variables=4
185+ %%%mzn-stat: propagators=1
186+ %%%mzn-stat: solveTime=0.001
187+ %%%mzn-stat: peakMem=1.00
188+ %%%mzn-stat-end
147189```
148190
149- The output format follows the [ FlatZinc specification] ( https://docs.minizinc.dev/en/stable/fzn-spec.html#output ) :
150- - Each variable assignment on its own line: ` varname = value; `
151- - Separator line ` ---------- ` marks the end of a solution
152- - ` =====UNSATISFIABLE===== ` when no solution exists
153- - ` =====UNKNOWN===== ` when satisfiability cannot be determined
191+ All statistics are automatically extracted from Selen's solver:
192+ - ** Standard** (FlatZinc spec): solutions, nodes, failures, solveTime (seconds), peakMem (MB)
193+ - ** Extended** : propagations, variables, propagators
154194
155195## Using with MiniZinc
156196
@@ -219,17 +259,32 @@ Zelen has been tested on 851 real-world FlatZinc files from the OR-Tools test su
219259
220260## Examples
221261
222- Check the ` examples/ ` directory for more complete examples :
262+ The repository includes comprehensive examples demonstrating different aspects of the library :
223263
224- ``` bash
225- # Basic FlatZinc parsing and solving
226- cargo run --example flatzinc_simple
264+ ### Basic Usage
265+ - ** ` simple_usage.rs ` ** - Basic constraint solving with FlatZincContext API
266+ - ** ` clean_api.rs ` ** - High-level FlatZincSolver API with automatic output formatting
267+ - ** ` solver_demo.rs ` ** - Demonstrates solving various constraint problem types
268+
269+ ### FlatZinc Integration
270+ - ** ` flatzinc_simple.rs ` ** - Simple FlatZinc model solving
271+ - ** ` flatzinc_output.rs ` ** - FlatZinc-compliant output formatting
227272
228- # FlatZinc-compliant output formatting
229- cargo run --example flatzinc_output
273+ ### Multiple Solutions & Configuration
274+ - ** ` multiple_solutions.rs ` ** - Enumerate multiple solutions with configurable limits
275+ - ** ` spec_compliance.rs ` ** - FlatZinc specification compliance demonstration
276+ - ** ` optimization_test.rs ` ** - Minimize/maximize with optimal and intermediate solutions
230277
231- # Complete solver demo with multiple problem types
232- cargo run --example solver_demo
278+ ### Statistics & Monitoring
279+ - ** ` enhanced_statistics.rs ` ** - All available solver statistics from Selen
280+ - ** ` statistics_units.rs ` ** - Statistics unit verification (seconds, megabytes)
281+
282+ Run any example with:
283+ ``` bash
284+ cargo run --example < name>
285+ # For instance:
286+ cargo run --example clean_api
287+ cargo run --example multiple_solutions
233288```
234289
235290## Testing
0 commit comments