Struct MultiBuilder

Source
pub struct MultiBuilder { /* private fields */ }
Expand description

Provides a way to build a Multi job using the builder pattern.

Implementations§

Source§

impl MultiBuilder

Source

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}
Source

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}
Source

pub fn dimension(self, func: impl FnOnce(&mut Dimensions)) -> Self

A simple api to associate arbitrary property within the job.

Source

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.

Source

pub fn build(self) -> GenericResult<Arc<Multi>>

Builds Multi job as shared reference.

Source

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

Source§

fn default() -> MultiBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V