Skip to content

Commit 902958f

Browse files
authored
Merge pull request #23 from radevgit/zinc_phase3
Zinc phase3
2 parents d6b200d + 5874ea0 commit 902958f

File tree

72 files changed

+12002
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+12002
-12
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
**/*.rs.bk
66
clippy.txt
77
/coverage/results
8-
/src/zinc/flatzinc
8+
/zinc
99

1010
# Binary executables and object files
1111
*.exe

CURRENT_STATUS.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Selen FlatZinc Test Status - October 2, 2025
2+
3+
## 🎉 Current Success Rate: **92.8%** (790/851 files)
4+
5+
### Progress Summary
6+
- **Session Start**: 727/851 (85.4%)
7+
- **After Cumulative + Quick Wins**: 761/851 (89.4%)
8+
- **After Array Element Fix**: 790/851 (92.8%)
9+
- **Total Improvement**: +63 files (+7.4 percentage points)
10+
11+
### Batch-by-Batch Results
12+
13+
| Batch | Before | After | Change | Rate |
14+
|-------|--------|-------|--------|------|
15+
| 01 | 84/86 | 85/86 | +1 | 98.8% |
16+
| 02 | 65/86 | 76/86 | +11 | 88.4% |
17+
| 03 | 77/86 | 79/86 | +2 | 91.9% |
18+
| 04 | 79/86 | 80/86 | +1 | 93.0% |
19+
| 05 | 70/86 | 77/86 | +7 | 89.5% |
20+
| 06 | 78/86 | 82/86 | +4 | 95.3% |
21+
| 07 | 65/86 | 74/86 | +9 | 86.0% |
22+
| 08 | 75/86 | 81/86 | +6 | 94.2% |
23+
| 09 | 67/86 | 77/86 | +10 | 89.5% |
24+
| 10 | 67/81 | 79/81 | +12 | 97.5% |
25+
26+
### Recent Changes (Array Element Fix)
27+
**Files Modified**: `src/flatzinc/mapper/constraints/element.rs`
28+
29+
**Impact**: +29 files (761 → 790)
30+
31+
**Changes Made**:
32+
- Updated `array_var_int_element` to use `get_var_or_const()` for index and value
33+
- Updated `array_int_element` to use `get_var_or_const()` for index and value
34+
- Updated `array_var_bool_element` to use `get_var_or_const()` for index and value
35+
- Updated `array_bool_element` to use `get_var_or_const()` for index and value
36+
37+
**What this enables**:
38+
- Support for `ArrayAccess` expressions in element constraints (e.g., `array[x[i]]`)
39+
- Support for integer/boolean literals in index/value positions
40+
- Simplified code by removing manual pattern matching
41+
42+
### Known Remaining Issues (61 failures)
43+
44+
#### High Priority (Quick Wins):
45+
1. **Parse Errors** (~5 files): "Expected Int, found IntLiteral(1)"
46+
- Parser issue with type annotations
47+
48+
2. **Domain Size Exceeded** (2 files): Variables with domains > 10M
49+
- `arrow.fzn`: [123456789, 987654321]
50+
- `contains_array.fzn`: [0, 999999999]
51+
52+
3. **Reified Constraint Issues** (~3 files):
53+
- `int_eq_reif` with unsupported argument types
54+
- `int_ne_reif` with unsupported argument types
55+
56+
4. **Set Literals in Arrays** (2 files):
57+
- `bus_scheduling_csplib.fzn`: SetLit in array elements
58+
- `combinatorial_auction.fzn`: SetLit in array elements
59+
60+
#### Medium Priority:
61+
5. **global_cardinality_low_up_closed** (1 file): Not implemented
62+
63+
6. **IntLit in Specific Contexts** (1 file):
64+
- `buckets.fzn`: IntLit(0) not accepted somewhere
65+
66+
### Distance to Milestones
67+
- **90%**: ✅ ACHIEVED! (target was 765/851)
68+
- **95%**: Need +19 files (809/851)
69+
- **96%**: Need +27 files (817/851)
70+
71+
### Next Steps Options
72+
A. **Push for 95%** - Fix parse errors + domain issues + reified constraints
73+
B. **Analyze remaining 61 failures** - Categorize and prioritize
74+
C. **Document current state** - Create comprehensive guide
75+
76+
---
77+
*Last Updated: October 2, 2025*
78+
*Array element fix completed*

FAILURE_ANALYSIS.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Failure Analysis - 65 Remaining Issues
2+
3+
## Category Breakdown
4+
5+
### 1. **Domain Size Exceeded** (21 files) ⚠️
6+
Variables with domains > 10,000,000 elements.
7+
8+
**Files:**
9+
- arrow.fzn: [123456789, 987654321] (864M elements)
10+
- contains_array.fzn: [0, 999999999] (1B elements)
11+
- curious_set_of_integers.fzn: [0, 100000000] (100M elements)
12+
- digits_of_the_square.fzn: [1000000, 99980001] (98M elements)
13+
- divisible_by_9_trough_1.fzn: [0, 999999999] (1B elements)
14+
- enigma_1570.fzn: [0, 32461758] (32M elements)
15+
- enigma_portuguese_squares.fzn: [1, 1000000000] (1B elements)
16+
- euler_2.fzn: [0, 10000000] (10M elements)
17+
- euler_9.fzn: [0, 125000000] (125M elements)
18+
- four_power.fzn: [1, 64000000] (64M elements)
19+
- grocery.fzn: [0, 359425431] (359M elements)
20+
- magic_modulo_number.fzn: [0, 10000000] (10M elements)
21+
- number_square.fzn: [110000000, 199999999] (90M elements)
22+
- seven11.fzn: [0, 359425431] (359M elements)
23+
- shopping_basket2.fzn: [6, 30000015] (30M elements)
24+
- shopping_basket.fzn: [0, 10000435] (10M elements)
25+
- square_root_of_wonderful.fzn: [123454321, 999999999] (876M elements)
26+
27+
**Solution:** Increase MAX_DOMAIN_SIZE or implement sparse domain representation
28+
29+
### 2. **Parse Errors** (17 files) 🔴
30+
Parser issues with various constructs.
31+
32+
**Type A - "Expected Int, found IntLiteral(1)"** (11 files):
33+
- bokus_competition.fzn (line 350)
34+
- common.fzn (line 173)
35+
- connected.fzn (line 78)
36+
- in_set.fzn (line 1)
37+
- open_alldifferent.fzn (line 4)
38+
- open_among.fzn (line 11)
39+
- open_atleast.fzn (line 9)
40+
- open_atmost.fzn (line 9)
41+
- open_global_cardinality.fzn (line 22)
42+
- open_global_cardinality_low_up.fzn (line 23)
43+
- roots_test.fzn (line 26)
44+
- set_covering4b.fzn (line 2)
45+
46+
**Type B - "Expected RightBracket, found LeftParen"** (3 files):
47+
- packing.fzn (line 20976)
48+
- queens_viz.fzn (line 12)
49+
- seg_fault.fzn (line 2736)
50+
51+
**Type C - Other** (3 files):
52+
- debruijn_no_repetition.fzn: Expected RightParen, found LeftParen
53+
- kaprekars_constant*.fzn (3 files): Unexpected token in expression: RightBrace
54+
- regular_test.fzn: Lexical Error - Unexpected character: '/'
55+
56+
**Solution:** Fix parser to handle these edge cases
57+
58+
### 3. **SetLit in Array Elements** (15 files) 🟡
59+
Array elements contain set literals like {1, 2, 3}.
60+
61+
**Files:**
62+
- bus_scheduling_csplib.fzn
63+
- combinatorial_auction.fzn
64+
- exact_cover_dlx.fzn
65+
- hitting_set.fzn
66+
- itemset_mining.fzn
67+
- map_coloring_with_costs.fzn
68+
- maximal_independent_sets.fzn
69+
- mixing_party.fzn
70+
- number_of_regions.fzn
71+
- optimal_picking_elements_from_each_list.fzn
72+
- partial_latin_square.fzn
73+
- sat.fzn
74+
- scene_allocation.fzn
75+
- set_covering2.fzn
76+
- set_covering5.fzn
77+
78+
**Solution:** Support SetLit in array literal expressions in mapper.rs
79+
80+
### 4. **IntLit Mapping Errors** (6 files) 🟢 EASY FIX
81+
"Expected variable identifier or array access, got: IntLit(X)"
82+
83+
**Files:**
84+
- buckets.fzn: IntLit(0)
85+
- einstein_opl.fzn: IntLit(1)
86+
- houses.fzn: IntLit(1)
87+
- lecture_series.fzn: IntLit(1)
88+
- olympic.fzn: IntLit(3)
89+
- timeslots_for_songs.fzn: IntLit(3)
90+
- zebra_inverse.fzn: IntLit(1)
91+
92+
**Solution:** Find where get_var() is used instead of get_var_or_const()
93+
94+
### 5. **ArrayAccess in Array Elements** (2 files) 🟡
95+
Array initialization contains array access like a[1].
96+
97+
**Files:**
98+
- enigma_1575.fzn: ArrayAccess { array: "days", index: IntLit(3) }
99+
- locker.fzn: ArrayAccess { array: "a_d1", index: IntLit(1) }
100+
101+
**Solution:** Support ArrayAccess in array literal expressions in mapper.rs
102+
103+
### 6. **Reified Constraint Issues** (2 files) 🟡
104+
Unsupported argument types for reified constraints.
105+
106+
**Files:**
107+
- battleships_6.fzn: int_eq_reif (line 1509)
108+
- bug_unsat.fzn: int_ne_reif (line 7488)
109+
110+
**Solution:** Check and fix reified constraint mappers
111+
112+
### 7. **Unsupported Constraints** (1 file) 🟠
113+
Not implemented.
114+
115+
**Files:**
116+
- bobs_sale.fzn: global_cardinality_low_up_closed
117+
118+
**Solution:** Implement this global constraint
119+
120+
### 8. **Other Mapping Errors** (1 file) ��
121+
Specific mapping issues.
122+
123+
**Files:**
124+
- smullyan_lion_and_unicorn.fzn: Expected array literal in array_bool_element
125+
126+
**Solution:** Investigate specific case
127+
128+
---
129+
130+
## Priority Ranking
131+
132+
### 🟢 HIGH PRIORITY (Quick Wins - Est. +7 files)
133+
1. **Fix IntLit mapping errors** (7 files)
134+
- Find remaining get_var() that should be get_var_or_const()
135+
- Estimated effort: 10 minutes
136+
- Impact: +7 files
137+
138+
### 🟡 MEDIUM PRIORITY (Est. +17 files)
139+
2. **Support SetLit in arrays** (15 files)
140+
- Add SetLit case in array literal handling
141+
- Estimated effort: 30 minutes
142+
- Impact: +15 files
143+
144+
3. **Support ArrayAccess in arrays** (2 files)
145+
- Add ArrayAccess case in array literal handling
146+
- Estimated effort: 15 minutes
147+
- Impact: +2 files
148+
149+
### 🟠 LOW PRIORITY (Est. +3 files)
150+
4. **Fix reified constraints** (2 files)
151+
- Debug int_eq_reif and int_ne_reif
152+
- Estimated effort: 30 minutes
153+
- Impact: +2 files
154+
155+
5. **Implement global_cardinality_low_up_closed** (1 file)
156+
- Estimated effort: 1 hour
157+
- Impact: +1 file
158+
159+
### ⚠️ DEFERRED (21 files - architectural decision needed)
160+
6. **Domain size limit**
161+
- Requires architectural change (sparse domains or higher limit)
162+
- Estimated effort: 2-4 hours
163+
- Impact: +21 files
164+
165+
### 🔴 COMPLEX (17 files - parser work)
166+
7. **Fix parser errors**
167+
- Requires parser fixes for edge cases
168+
- Estimated effort: 2-3 hours
169+
- Impact: +17 files
170+
171+
---
172+
173+
## Recommended Next Steps
174+
175+
**Option A: Quick Push to 95%** (Recommended)
176+
1. Fix IntLit mapping errors → 797/851 (93.7%)
177+
2. Support SetLit in arrays → 812/851 (95.4%) ✅ **95% ACHIEVED!**
178+
179+
**Option B: Maximum Impact**
180+
1. Do Option A (Quick push to 95%)
181+
2. Support ArrayAccess in arrays → 814/851 (95.7%)
182+
3. Fix reified constraints → 816/851 (95.9%)
183+
184+
**Option C: Complete Coverage** (Long term)
185+
- All of Option B
186+
- Implement missing constraint
187+
- Fix parser errors
188+
- Address domain size limit
189+
→ Target: 851/851 (100%)
190+

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This library provides efficient algorithms and data structures for solving const
2424
- **Conditional**: `if_then(condition, constraint)`, `if_then_else(condition, then_constraint, else_constraint)`
2525

2626
**Programmatic version of constraints**
27-
```
27+
```rust
2828
m.new(x.lt(y)); // x < y
2929
m.new(y.le(z)); // y <= z
3030
m.new(z.gt(5)); // z > 5
@@ -35,7 +35,7 @@ m.new(z.div(y).ne(0)); // z / y != 0
3535
```
3636

3737
**Mathematical syntax with post! macro**
38-
```
38+
```rust
3939
post!(m, x < y); // x < y
4040
post!(m, y <= z); // y <= z
4141
post!(m, z > int(5)); // z > 5
@@ -45,6 +45,16 @@ post!(m, x * y == int(12)); // x * y == 12
4545
post!(m, z / y != int(0)); // z / y != 0
4646
```
4747

48+
**Import FlatZinc `.fzn` file**
49+
```rust
50+
use selen::prelude::*;
51+
let mut model = Model::default();
52+
model.from_flatzinc_file("puzzle.fzn")?;
53+
let solution = model.solve()?;
54+
println!("Solution: {:?}", solution);
55+
```
56+
57+
4858
## Installation
4959

5060
Add this to your `Cargo.toml`:
@@ -54,6 +64,8 @@ Add this to your `Cargo.toml`:
5464
selen = "0.8.6"
5565
```
5666

67+
## Examples
68+
5769
```
5870
🧩 Solving Platinum Blonde puzzle:
5971
📊 Puzzle stats: 17 clues given, 64 empty cells
@@ -79,8 +91,6 @@ Puzzle: Solution:
7991
8092
```
8193

82-
## Examples
83-
8494
### Core Problems
8595
```bash
8696
cargo run --release --example sudoku # Classic 9x9 Sudoku solver

comment_passing_tests.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Run each batch and capture which tests pass/fail
4+
for batch in {01..10}; do
5+
echo "Processing batch $batch..."
6+
7+
# Run the test and capture output
8+
test_output=$(cargo test --release --test test_flatzinc_batch_$batch -- --nocapture 2>&1)
9+
10+
# Extract passing test files (lines with ✓)
11+
passing_tests=$(echo "$test_output" | grep "" | sed 's/.*✓ //' | sed 's/\.fzn.*/\.fzn/')
12+
13+
# Get the test file path
14+
test_file="tests/test_flatzinc_batch_${batch}.rs"
15+
16+
if [ ! -f "$test_file" ]; then
17+
echo "Warning: $test_file not found"
18+
continue
19+
fi
20+
21+
# Create backup
22+
cp "$test_file" "${test_file}.backup"
23+
24+
# Comment out each passing test
25+
while IFS= read -r passing_test; do
26+
if [ -n "$passing_test" ]; then
27+
# Escape special characters for sed
28+
escaped_test=$(echo "$passing_test" | sed 's/[.[\*^$()+?{|]/\\&/g')
29+
30+
# Comment out the line with this test file
31+
sed -i "s|^\(.*\"$escaped_test\".*\)|// \1 // ✓ PASSING|" "$test_file"
32+
fi
33+
done <<< "$passing_tests"
34+
35+
echo " ✓ Commented out passing tests in $test_file"
36+
done
37+
38+
echo ""
39+
echo "Done! All passing tests have been commented out."
40+
echo "To restore, run: for f in tests/test_flatzinc_batch_*.rs.backup; do mv \"\$f\" \"\${f%.backup}\"; done"

0 commit comments

Comments
 (0)