Skip to content

Commit f5dc0de

Browse files
committed
Add examples to docs
1 parent 91b390a commit f5dc0de

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

src/builder/var.rs

+33-10
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ impl Default for VarBuilder<'_> {
4545

4646
impl<'a> VarBuilder<'a> {
4747
/// Sets the variable to be an integer variable.
48-
/// The bounds are inclusive.
49-
///
48+
///
5049
/// # Example
51-
///
50+
///
5251
/// ```rust
5352
/// 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]
5655
/// ```
5756
pub fn int<B: RangeBounds<isize>>(mut self, bounds: B) -> Self {
5857
match bounds.start_bound() {
@@ -74,6 +73,13 @@ impl<'a> VarBuilder<'a> {
7473
}
7574

7675
/// 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+
/// ```
7783
pub fn bin(mut self) -> Self {
7884
self.lb = 0.0;
7985
self.ub = 1.0;
@@ -82,6 +88,15 @@ impl<'a> VarBuilder<'a> {
8288
}
8389

8490
/// 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+
/// ```
85100
pub fn cont<B: RangeBounds<f64>>(mut self, bounds: B) -> Self {
86101
match bounds.start_bound() {
87102
std::ops::Bound::Included(&lb) => self.lb = lb,
@@ -102,17 +117,25 @@ impl<'a> VarBuilder<'a> {
102117
}
103118

104119
/// 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 {
106129
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,
109132
std::ops::Bound::Unbounded => {
110133
self.lb = f64::NEG_INFINITY;
111134
}
112135
}
113136
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,
116139
std::ops::Bound::Unbounded => {
117140
self.ub = f64::INFINITY;
118141
}

0 commit comments

Comments
 (0)