pub struct MultiBuilder { /* private fields */ }
Expand description
Provides a way to build a Multi job using the builder pattern.
Implementations§
Source§impl MultiBuilder
impl MultiBuilder
Sourcepub fn id(self, id: &str) -> Self
pub fn id(self, id: &str) -> Self
Sets a job id dimension.
Examples found in repository?
examples/pdptw.rs (line 28)
22fn define_problem(goal: GoalContext, transport: Arc<dyn TransportCost>) -> GenericResult<Problem> {
23 // build two PUDO (pick up/drop off) jobs with demand=1 and permissive time windows (just to show API usage)
24 let pudos = (1..=2)
25 .map(|idx| {
26 let location_idx = if idx == 1 { 1 } else { 3 };
27 MultiBuilder::default()
28 .id(format!("pudo{idx}").as_str())
29 .add_job(
30 SingleBuilder::default()
31 .demand(Demand::pudo_pickup(1))
32 .times(vec![TimeWindow::new(0., 1000.)])?
33 .duration(10.)?
34 .location(location_idx)?
35 .build()?,
36 )
37 .add_job(
38 SingleBuilder::default()
39 .demand(Demand::pudo_delivery(1))
40 .times(vec![TimeWindow::new(0., 1000.)])?
41 .duration(10.)?
42 .location(location_idx + 1)?
43 .build()?,
44 )
45 .build_as_job()
46 })
47 .collect::<Result<Vec<_>, _>>()?;
48
49 // define a single vehicle with limited capacity
50 let vehicle = VehicleBuilder::default()
51 .id("v1".to_string().as_str())
52 .add_detail(
53 VehicleDetailBuilder::default()
54 // vehicle starts at location with index 0 in routing matrix
55 .set_start_location(0)
56 .set_start_time(0.)
57 // vehicle should return to location with index 0
58 .set_end_location(0)
59 .set_end_time(10000.)
60 .build()?,
61 )
62 // the vehicle has capacity=1, so it is forced to do delivery after each pickup
63 .capacity(SingleDimLoad::new(1))
64 .build()?;
65
66 ProblemBuilder::default()
67 .add_jobs(pudos.into_iter())
68 .add_vehicles(once(vehicle))
69 .with_goal(goal)
70 .with_transport_cost(transport)
71 .build()
72}
Sourcepub fn add_job(self, single: Single) -> Self
pub fn add_job(self, single: Single) -> Self
Adds a Single as sub-job.
Examples found in repository?
examples/pdptw.rs (lines 29-36)
22fn define_problem(goal: GoalContext, transport: Arc<dyn TransportCost>) -> GenericResult<Problem> {
23 // build two PUDO (pick up/drop off) jobs with demand=1 and permissive time windows (just to show API usage)
24 let pudos = (1..=2)
25 .map(|idx| {
26 let location_idx = if idx == 1 { 1 } else { 3 };
27 MultiBuilder::default()
28 .id(format!("pudo{idx}").as_str())
29 .add_job(
30 SingleBuilder::default()
31 .demand(Demand::pudo_pickup(1))
32 .times(vec![TimeWindow::new(0., 1000.)])?
33 .duration(10.)?
34 .location(location_idx)?
35 .build()?,
36 )
37 .add_job(
38 SingleBuilder::default()
39 .demand(Demand::pudo_delivery(1))
40 .times(vec![TimeWindow::new(0., 1000.)])?
41 .duration(10.)?
42 .location(location_idx + 1)?
43 .build()?,
44 )
45 .build_as_job()
46 })
47 .collect::<Result<Vec<_>, _>>()?;
48
49 // define a single vehicle with limited capacity
50 let vehicle = VehicleBuilder::default()
51 .id("v1".to_string().as_str())
52 .add_detail(
53 VehicleDetailBuilder::default()
54 // vehicle starts at location with index 0 in routing matrix
55 .set_start_location(0)
56 .set_start_time(0.)
57 // vehicle should return to location with index 0
58 .set_end_location(0)
59 .set_end_time(10000.)
60 .build()?,
61 )
62 // the vehicle has capacity=1, so it is forced to do delivery after each pickup
63 .capacity(SingleDimLoad::new(1))
64 .build()?;
65
66 ProblemBuilder::default()
67 .add_jobs(pudos.into_iter())
68 .add_vehicles(once(vehicle))
69 .with_goal(goal)
70 .with_transport_cost(transport)
71 .build()
72}
Sourcepub fn dimension(self, func: impl FnOnce(&mut Dimensions)) -> Self
pub fn dimension(self, func: impl FnOnce(&mut Dimensions)) -> Self
A simple api to associate arbitrary property within the job.
Sourcepub fn permutation(self, permutation: impl JobPermutation + 'static) -> Self
pub fn permutation(self, permutation: impl JobPermutation + 'static) -> Self
Sets a permutation logic which tells allowed order of sub-jobs assignment. If omitted, sub-jobs can be assigned only in the order of addition.
Sourcepub fn build_as_job(self) -> GenericResult<Job>
pub fn build_as_job(self) -> GenericResult<Job>
Builds a Job.
Examples found in repository?
examples/pdptw.rs (line 45)
22fn define_problem(goal: GoalContext, transport: Arc<dyn TransportCost>) -> GenericResult<Problem> {
23 // build two PUDO (pick up/drop off) jobs with demand=1 and permissive time windows (just to show API usage)
24 let pudos = (1..=2)
25 .map(|idx| {
26 let location_idx = if idx == 1 { 1 } else { 3 };
27 MultiBuilder::default()
28 .id(format!("pudo{idx}").as_str())
29 .add_job(
30 SingleBuilder::default()
31 .demand(Demand::pudo_pickup(1))
32 .times(vec![TimeWindow::new(0., 1000.)])?
33 .duration(10.)?
34 .location(location_idx)?
35 .build()?,
36 )
37 .add_job(
38 SingleBuilder::default()
39 .demand(Demand::pudo_delivery(1))
40 .times(vec![TimeWindow::new(0., 1000.)])?
41 .duration(10.)?
42 .location(location_idx + 1)?
43 .build()?,
44 )
45 .build_as_job()
46 })
47 .collect::<Result<Vec<_>, _>>()?;
48
49 // define a single vehicle with limited capacity
50 let vehicle = VehicleBuilder::default()
51 .id("v1".to_string().as_str())
52 .add_detail(
53 VehicleDetailBuilder::default()
54 // vehicle starts at location with index 0 in routing matrix
55 .set_start_location(0)
56 .set_start_time(0.)
57 // vehicle should return to location with index 0
58 .set_end_location(0)
59 .set_end_time(10000.)
60 .build()?,
61 )
62 // the vehicle has capacity=1, so it is forced to do delivery after each pickup
63 .capacity(SingleDimLoad::new(1))
64 .build()?;
65
66 ProblemBuilder::default()
67 .add_jobs(pudos.into_iter())
68 .add_vehicles(once(vehicle))
69 .with_goal(goal)
70 .with_transport_cost(transport)
71 .build()
72}
Trait Implementations§
Source§impl Default for MultiBuilder
impl Default for MultiBuilder
Source§fn default() -> MultiBuilder
fn default() -> MultiBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for MultiBuilder
impl !RefUnwindSafe for MultiBuilder
impl Send for MultiBuilder
impl Sync for MultiBuilder
impl Unpin for MultiBuilder
impl !UnwindSafe for MultiBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more