Skip to content

Commit aedf922

Browse files
committed
Added int_lin_* and float_lin_*. Refactored to modularization consept.
1 parent 3087aff commit aedf922

File tree

15 files changed

+4094
-1464
lines changed

15 files changed

+4094
-1464
lines changed

MACRO_DEPRECATION.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Constraint Macros Deprecation Guide
2+
3+
**Version**: 0.9.3
4+
**Status**: DEPRECATED
5+
**Removal Target**: Future release (likely 1.0.0)
6+
7+
## ⚠️ What's Deprecated
8+
9+
The constraint macro system (`post!`, `postall!`, and related macros) is now deprecated due to:
10+
- Difficult maintenance
11+
- Limited capabilities compared to direct API
12+
- Complexity in error messages
13+
- Inconsistent behavior with Rust's type system
14+
15+
## 📋 Deprecated Items
16+
17+
### Modules
18+
- `constraints::macros` - The entire macro system module
19+
- `constraint_macros` - The compatibility re-export module
20+
21+
### Types
22+
- `ConstraintRef` - Used internally by macros
23+
24+
### Macros
25+
- `post!` - Main constraint posting macro
26+
- `postall!` - Batch constraint posting macro
27+
- `post_arithmetic!` - Internal dispatch macro
28+
- `post_comparison!` - Internal dispatch macro
29+
- `post_logical!` - Internal dispatch macro
30+
- `post_global!` - Internal dispatch macro
31+
32+
## 🔄 Migration Guide
33+
34+
### Arithmetic Operations
35+
36+
**Before (Deprecated):**
37+
```rust
38+
post!(model, x + y == z);
39+
post!(model, a - b == c);
40+
post!(model, x * y == z);
41+
```
42+
43+
**After (Recommended):**
44+
```rust
45+
let sum = model.add(x, y);
46+
model.props.equals(sum, z);
47+
48+
let diff = model.sub(a, b);
49+
model.props.equals(diff, c);
50+
51+
let product = model.mul(x, y);
52+
model.props.equals(product, z);
53+
```
54+
55+
### Comparisons
56+
57+
**Before (Deprecated):**
58+
```rust
59+
post!(model, x == y);
60+
post!(model, x < y);
61+
post!(model, x <= y);
62+
```
63+
64+
**After (Recommended):**
65+
```rust
66+
model.props.equals(x, y);
67+
model.props.less_than(x, y);
68+
model.props.less_than_or_equals(x, y);
69+
```
70+
71+
### Sum Constraints
72+
73+
**Before (Deprecated):**
74+
```rust
75+
post!(model, sum([x, y, z]) == 10);
76+
```
77+
78+
**After (Recommended):**
79+
```rust
80+
let total = model.sum(&[x, y, z]);
81+
model.props.equals(total, Val::ValI(10));
82+
```
83+
84+
### Linear Constraints
85+
86+
**Before (Deprecated):**
87+
```rust
88+
// This was difficult/impossible with macros
89+
```
90+
91+
**After (Recommended):**
92+
```rust
93+
// Direct, clean API
94+
model.int_lin_eq(&[2, 3, -1], &[x, y, z], 10); // 2x + 3y - z = 10
95+
model.int_lin_le(&[1, 1, 1], &[x, y, z], 20); // x + y + z ≤ 20
96+
```
97+
98+
### Global Constraints
99+
100+
**Before (Deprecated):**
101+
```rust
102+
post!(model, alldiff [x, y, z]);
103+
post!(model, element [idx, array, result]);
104+
```
105+
106+
**After (Recommended):**
107+
```rust
108+
model.props.all_different(&[x, y, z]);
109+
model.props.element(array.to_vec(), idx, result);
110+
```
111+
112+
### Boolean Logic
113+
114+
**Before (Deprecated):**
115+
```rust
116+
post!(model, and [a, b, c] == result);
117+
post!(model, or [a, b] == result);
118+
```
119+
120+
**After (Recommended):**
121+
```rust
122+
let result = model.bool_and(&[a, b, c]);
123+
let result = model.bool_or(&[a, b]);
124+
```
125+
126+
### Batch Posting
127+
128+
**Before (Deprecated):**
129+
```rust
130+
postall!(model,
131+
x < y,
132+
y < z,
133+
x + y == 10
134+
);
135+
```
136+
137+
**After (Recommended):**
138+
```rust
139+
model.props.less_than(x, y);
140+
model.props.less_than(y, z);
141+
let sum = model.add(x, y);
142+
model.props.equals(sum, Val::ValI(10));
143+
```
144+
145+
## ✅ Benefits of Direct API
146+
147+
1. **Better Type Safety**: Rust's type system works naturally
148+
2. **Clearer Error Messages**: Standard Rust compilation errors
149+
3. **IDE Support**: Full autocomplete and documentation
150+
4. **More Capabilities**: Access to all constraint variants (reified, linear, etc.)
151+
5. **Easier to Maintain**: Standard Rust code, not macro magic
152+
6. **Better Performance**: No macro expansion overhead
153+
154+
## 📚 API Reference
155+
156+
All constraint methods are now organized in `constraints::api`:
157+
158+
- **Arithmetic**: `constraints::api::arithmetic`
159+
- `add`, `sub`, `mul`, `div`, `modulo`, `abs`, `min`, `max`, `sum`
160+
161+
- **Boolean**: `constraints::api::boolean`
162+
- `bool_and`, `bool_or`, `bool_not`, `bool_clause`
163+
164+
- **Reified**: `constraints::api::reified`
165+
- `int_eq_reif`, `int_ne_reif`, `int_lt_reif`, `int_le_reif`, etc.
166+
- `float_eq_reif`, `float_ne_reif`, `float_lt_reif`, etc.
167+
168+
- **Linear**: `constraints::api::linear`
169+
- `int_lin_eq`, `int_lin_le`, `int_lin_ne` (and reified versions)
170+
- `float_lin_eq`, `float_lin_le`, `float_lin_ne` (and reified versions)
171+
172+
- **Conversion**: `constraints::api::conversion`
173+
- `int2float`, `float2int_floor`, `float2int_ceil`, `float2int_round`
174+
175+
- **Array**: `constraints::api::array`
176+
- `array_float_minimum`, `array_float_maximum`, `array_float_element`
177+
178+
## 🗓️ Timeline
179+
180+
- **0.9.3**: Macros marked as deprecated (current)
181+
- **0.10.x**: Macros removed (target)
182+
183+
## 💡 Need Help?
184+
185+
If you have code using the macro system and need help migrating:
186+
1. Check the examples in `examples/` directory for direct API usage
187+
2. See the constraint API documentation in `src/constraints/api/`
188+
3. The deprecation warnings show the recommended alternatives
189+
4. All macro functionality is available (and more) through the direct API

src/constraint_macros.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
//! Constraint macros compatibility layer
1+
//! Constraint macros compatibility layer (DEPRECATED)
2+
//!
3+
//! **⚠️ DEPRECATED**: Constraint macros are deprecated and will be removed in a future release.
4+
//!
5+
//! **Please migrate to the constraint API methods**:
6+
//! - `model.add(x, y)` instead of macro syntax
7+
//! - `model.props.equals(x, y)` for constraints
8+
//! - See the `constraints::api` module for all available methods
29
//!
310
//! This module provides backward compatibility by re-exporting the organized
411
//! constraint macros from the constraints/macros module.
512
613
// Re-export the ConstraintRef type
14+
#[deprecated(since = "0.9.3", note = "Part of deprecated constraint macros.")]
715
pub use crate::constraints::macros::ConstraintRef;
816

917
// Re-export all categorized macros to maintain compatibility
18+
#[deprecated(since = "0.9.3", note = "Constraint macros are deprecated. Use constraint API methods directly.")]
1019
pub use crate::constraints::macros::*;
1120

1221
// Batch posting macros
1322
#[doc(hidden)]
23+
#[deprecated(since = "0.9.3", note = "The `postall!` macro is deprecated. Post constraints individually using constraint API methods. Will be removed in a future release.")]
1424
#[macro_export]
1525
macro_rules! postall {
1626
// Use simple comma-separated arguments

0 commit comments

Comments
 (0)