Struct vrp_core::models::problem::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)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
fn define_problem(goal: GoalContext, transport: Arc<dyn TransportCost + Send + Sync>) -> GenericResult<Problem> {
    // build two PUDO (pick up/drop off) jobs with demand=1 and permissive time windows (just to show API usage)
    let pudos = (1..=2)
        .map(|idx| {
            let location_idx = if idx == 1 { 1 } else { 3 };
            MultiBuilder::default()
                .id(format!("pudo{idx}").as_str())
                .add_job(
                    SingleBuilder::default()
                        .demand(Demand::pudo_pickup(1))
                        .times(vec![TimeWindow::new(0., 1000.)])?
                        .duration(10.)?
                        .location(location_idx)?
                        .build()?,
                )
                .add_job(
                    SingleBuilder::default()
                        .demand(Demand::pudo_delivery(1))
                        .times(vec![TimeWindow::new(0., 1000.)])?
                        .duration(10.)?
                        .location(location_idx + 1)?
                        .build()?,
                )
                .build_as_job()
        })
        .collect::<Result<Vec<_>, _>>()?;

    // define a single vehicle with limited capacity
    let vehicle = VehicleBuilder::default()
        .id("v1".to_string().as_str())
        .add_detail(
            VehicleDetailBuilder::default()
                // vehicle starts at location with index 0 in routing matrix
                .set_start_location(0)
                .set_start_time(0.)
                // vehicle should return to location with index 0
                .set_end_location(0)
                .set_end_time(10000.)
                .build()?,
        )
        // the vehicle has capacity=1, so it is forced to do delivery after each pickup
        .capacity(SingleDimLoad::new(1))
        .build()?;

    ProblemBuilder::default()
        .add_jobs(pudos.into_iter())
        .add_vehicles(once(vehicle))
        .with_goal(goal)
        .with_transport_cost(transport)
        .build()
}
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)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
fn define_problem(goal: GoalContext, transport: Arc<dyn TransportCost + Send + Sync>) -> GenericResult<Problem> {
    // build two PUDO (pick up/drop off) jobs with demand=1 and permissive time windows (just to show API usage)
    let pudos = (1..=2)
        .map(|idx| {
            let location_idx = if idx == 1 { 1 } else { 3 };
            MultiBuilder::default()
                .id(format!("pudo{idx}").as_str())
                .add_job(
                    SingleBuilder::default()
                        .demand(Demand::pudo_pickup(1))
                        .times(vec![TimeWindow::new(0., 1000.)])?
                        .duration(10.)?
                        .location(location_idx)?
                        .build()?,
                )
                .add_job(
                    SingleBuilder::default()
                        .demand(Demand::pudo_delivery(1))
                        .times(vec![TimeWindow::new(0., 1000.)])?
                        .duration(10.)?
                        .location(location_idx + 1)?
                        .build()?,
                )
                .build_as_job()
        })
        .collect::<Result<Vec<_>, _>>()?;

    // define a single vehicle with limited capacity
    let vehicle = VehicleBuilder::default()
        .id("v1".to_string().as_str())
        .add_detail(
            VehicleDetailBuilder::default()
                // vehicle starts at location with index 0 in routing matrix
                .set_start_location(0)
                .set_start_time(0.)
                // vehicle should return to location with index 0
                .set_end_location(0)
                .set_end_time(10000.)
                .build()?,
        )
        // the vehicle has capacity=1, so it is forced to do delivery after each pickup
        .capacity(SingleDimLoad::new(1))
        .build()?;

    ProblemBuilder::default()
        .add_jobs(pudos.into_iter())
        .add_vehicles(once(vehicle))
        .with_goal(goal)
        .with_transport_cost(transport)
        .build()
}
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 + Send + Sync + '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)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
fn define_problem(goal: GoalContext, transport: Arc<dyn TransportCost + Send + Sync>) -> GenericResult<Problem> {
    // build two PUDO (pick up/drop off) jobs with demand=1 and permissive time windows (just to show API usage)
    let pudos = (1..=2)
        .map(|idx| {
            let location_idx = if idx == 1 { 1 } else { 3 };
            MultiBuilder::default()
                .id(format!("pudo{idx}").as_str())
                .add_job(
                    SingleBuilder::default()
                        .demand(Demand::pudo_pickup(1))
                        .times(vec![TimeWindow::new(0., 1000.)])?
                        .duration(10.)?
                        .location(location_idx)?
                        .build()?,
                )
                .add_job(
                    SingleBuilder::default()
                        .demand(Demand::pudo_delivery(1))
                        .times(vec![TimeWindow::new(0., 1000.)])?
                        .duration(10.)?
                        .location(location_idx + 1)?
                        .build()?,
                )
                .build_as_job()
        })
        .collect::<Result<Vec<_>, _>>()?;

    // define a single vehicle with limited capacity
    let vehicle = VehicleBuilder::default()
        .id("v1".to_string().as_str())
        .add_detail(
            VehicleDetailBuilder::default()
                // vehicle starts at location with index 0 in routing matrix
                .set_start_location(0)
                .set_start_time(0.)
                // vehicle should return to location with index 0
                .set_end_location(0)
                .set_end_time(10000.)
                .build()?,
        )
        // the vehicle has capacity=1, so it is forced to do delivery after each pickup
        .capacity(SingleDimLoad::new(1))
        .build()?;

    ProblemBuilder::default()
        .add_jobs(pudos.into_iter())
        .add_vehicles(once(vehicle))
        .with_goal(goal)
        .with_transport_cost(transport)
        .build()
}

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

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>,

§

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>,

§

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