@@ -45,14 +45,13 @@ impl Default for VarBuilder<'_> {
45
45
46
46
impl < ' a > VarBuilder < ' a > {
47
47
/// Sets the variable to be an integer variable.
48
- /// The bounds are inclusive.
49
- ///
48
+ ///
50
49
/// # Example
51
- ///
50
+ ///
52
51
/// ```rust
53
52
/// use russcip::prelude::*;
54
- ///
55
- /// let var = var().int(0..=10);
53
+ ///
54
+ /// let var = var().int(0..=10); // Integer variable with bounds [0, 10]
56
55
/// ```
57
56
pub fn int < B : RangeBounds < isize > > ( mut self , bounds : B ) -> Self {
58
57
match bounds. start_bound ( ) {
@@ -74,6 +73,13 @@ impl<'a> VarBuilder<'a> {
74
73
}
75
74
76
75
/// Sets the variable to be a binary variable.
76
+ ///
77
+ /// # Example
78
+ /// ```rust
79
+ /// use russcip::prelude::*;
80
+ ///
81
+ /// let var = var().bin(); // Binary variable
82
+ /// ```
77
83
pub fn bin ( mut self ) -> Self {
78
84
self . lb = 0.0 ;
79
85
self . ub = 1.0 ;
@@ -82,6 +88,15 @@ impl<'a> VarBuilder<'a> {
82
88
}
83
89
84
90
/// Sets the variable to be a continuous variable.
91
+ ///
92
+ /// # Example
93
+ /// ```rust
94
+ /// use russcip::prelude::*;
95
+ ///
96
+ /// let v1 = var().cont(0.0..); // Continuous variable with lower bound 0.0
97
+ /// let v2 = var().cont(..=10.0); // Continuous variable with upper bound 10.0
98
+ /// let v3 = var().cont(0.0..=10.0); // Continuous variable with bounds [0.0, 10.0]
99
+ /// ```
85
100
pub fn cont < B : RangeBounds < f64 > > ( mut self , bounds : B ) -> Self {
86
101
match bounds. start_bound ( ) {
87
102
std:: ops:: Bound :: Included ( & lb) => self . lb = lb,
@@ -102,17 +117,25 @@ impl<'a> VarBuilder<'a> {
102
117
}
103
118
104
119
/// Sets the variable to be an implicit integer variable.
105
- pub fn impl_int < B : RangeBounds < f64 > > ( mut self , bounds : B ) -> Self {
120
+ ///
121
+ /// # Example
122
+ ///
123
+ /// ```rust
124
+ /// use russcip::prelude::*;
125
+ ///
126
+ /// let var = var().impl_int(0..=10); // Implicit integer variable with bounds [0, 10]
127
+ /// ```
128
+ pub fn impl_int < B : RangeBounds < isize > > ( mut self , bounds : B ) -> Self {
106
129
match bounds. start_bound ( ) {
107
- std:: ops:: Bound :: Included ( & lb) => self . lb = lb,
108
- std:: ops:: Bound :: Excluded ( & lb) => self . lb = lb + 1.0 ,
130
+ std:: ops:: Bound :: Included ( & lb) => self . lb = lb as f64 ,
131
+ std:: ops:: Bound :: Excluded ( & lb) => self . lb = ( lb + 1 ) as f64 ,
109
132
std:: ops:: Bound :: Unbounded => {
110
133
self . lb = f64:: NEG_INFINITY ;
111
134
}
112
135
}
113
136
match bounds. end_bound ( ) {
114
- std:: ops:: Bound :: Included ( & ub) => self . ub = ub,
115
- std:: ops:: Bound :: Excluded ( & ub) => self . ub = ub - 1.0 ,
137
+ std:: ops:: Bound :: Included ( & ub) => self . ub = ub as f64 ,
138
+ std:: ops:: Bound :: Excluded ( & ub) => self . ub = ( ub - 1 ) as f64 ,
116
139
std:: ops:: Bound :: Unbounded => {
117
140
self . ub = f64:: INFINITY ;
118
141
}
0 commit comments