Enum Node

Source
pub enum Node {
    Bos(Bos),
    Eos(Eos),
    Middle(Middle),
}
Expand description

A node.

Variants§

§

Bos(Bos)

The BOS (Beginning of Sequence) node.

§

Eos(Eos)

The EOS (Ending of Sequence) node.

§

Middle(Middle)

The middle node.

Implementations§

Source§

impl Node

Source

pub const fn bos(preceding_edge_costs: Rc<Vec<i32>>) -> Self

Creates a BOS (Beginning of Sequence).

§Arguments
  • preceding_edge_costs - Preceding edge costs.
Source

pub const fn eos( preceding_step: usize, preceding_edge_costs: Rc<Vec<i32>>, best_preceding_node: usize, path_cost: i32, ) -> Self

Creates an EOS (Ending of Sequence).

§Arguments
  • preceding_step - An index of a preceding step.
  • preceding_edge_costs - Preceding edge costs.
  • best_preceding_node - An index of a best preceding node.
  • path_cost - A path cost.
Source

pub fn new( key: Box<dyn Input>, value: Box<dyn Any>, index_in_step: usize, preceding_step: usize, preceding_edge_costs: Rc<Vec<i32>>, best_preceding_node: usize, node_cost: i32, path_cost: i32, ) -> Self

Creates a node.

§Arguments
  • key - A key.
  • value - A value.
  • index_in_step - An index in the step.
  • preceding_step - An index of a preceding step.
  • preceding_edge_costs - Preceding edge costs.
  • best_preceding_node - An index of a best preceding node.
  • node_cost - A node cost.
  • path_cost - A path cost.
Source

pub fn new_with_entry( entry: Rc<Entry>, index_in_step: usize, preceding_step: usize, preceding_edge_costs: Rc<Vec<i32>>, best_preceding_node: usize, path_cost: i32, ) -> Result<Self, Error>

Creates a node with a vocabulary entry.

§Errors
  • When entry is BOS or EOS.
Source

pub fn key(&self) -> Option<&dyn Input>

Returns the key.

§Returns

The key.

Source

pub fn value(&self) -> Option<&dyn Any>

Returns the value.

§Returns

The value.

Examples found in repository?
examples/transfer_trains/main.rs (line 203)
189fn enumerate_trips(lattice: &Lattice, eos_node: Node, trip_capacity: usize) -> Vec<Trip> {
190    let iter = NBestIterator::new(lattice, eos_node, Box::new(Constraint::new()));
191    let mut trips = Vec::with_capacity(trip_capacity);
192    let mut duplication_checker = HashSet::<String>::new();
193    for path in iter {
194        if trips.len() >= trip_capacity || path.cost() >= 1440 {
195            break;
196        }
197
198        let mut trip = Trip {
199            sections: Vec::new(),
200            cost: 0,
201        };
202        for node in path.nodes() {
203            let section = if let Some(node_value) = node.value() {
204                if let Some(section) = node_value.downcast_ref::<Section>() {
205                    section
206                } else {
207                    continue;
208                }
209            } else {
210                continue;
211            };
212
213            if trip.sections.is_empty()
214                || trip
215                    .sections
216                    .last()
217                    .unwrap_or_else(|| unreachable!("trip.sections must not empty."))
218                    .train_number
219                    != section.train().number()
220            {
221                trip.sections.push(TripSection {
222                    train_number: section.train().number().to_string(),
223                    train_name: section.train().name().to_string(),
224                    departure_time: section.train().stops()[section.from()]
225                        .departure_time()
226                        .unwrap_or_else(|| unreachable!("departure_time must not None.")),
227                    departure_station: section.from(),
228                    arrival_time: section.train().stops()[section.to()]
229                        .arrival_time()
230                        .unwrap_or_else(|| unreachable!("arrival_time must not None.")),
231                    arrival_station: section.to(),
232                });
233            } else {
234                let last_section = trip
235                    .sections
236                    .last_mut()
237                    .unwrap_or_else(|| unreachable!("trip.sections must not empty."));
238                last_section.arrival_time = section.train().stops()[section.to()]
239                    .arrival_time()
240                    .unwrap_or_else(|| unreachable!("arrival_time must not None."));
241                last_section.arrival_station = section.to();
242            }
243        }
244        trip.cost = path.cost();
245
246        let first_section = trip
247            .sections
248            .first()
249            .unwrap_or_else(|| unreachable!("trip.sections must not empty."));
250        let last_section = trip
251            .sections
252            .last()
253            .unwrap_or_else(|| unreachable!("trip.sections must not empty."));
254        if duplication_checker.contains(&first_section.train_number)
255            || duplication_checker.contains(&last_section.train_number)
256        {
257            continue;
258        }
259        let _ = duplication_checker.insert(first_section.train_number.clone());
260        let _ = duplication_checker.insert(last_section.train_number.clone());
261        trips.push(trip);
262    }
263    trips
264}
Source

pub const fn index_in_step(&self) -> usize

Returns the index in the step.

§Returns

The index in the step.

Source

pub const fn preceding_step(&self) -> usize

Returns the preceding step.

§Returns

The preceding step.

Source

pub fn preceding_edge_costs(&self) -> &Vec<i32>

Returns the preceding edge costs.

§Returns

The preceding edge costs.

Source

pub const fn best_preceding_node(&self) -> usize

Returns the index of the best preceding node.

§Returns

The index of the best preceding node.

Source

pub fn node_cost(&self) -> i32

Returns the node cost.

§Returns

The node cost.

Source

pub const fn path_cost(&self) -> i32

Returns the path cost.

§Returns

The path cost.

Source

pub const fn is_bos(&self) -> bool

Returns true if this node is the BOS.

§Returns

true if this node is the BOS.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Node

Source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl !Send for Node

§

impl !Sync for Node

§

impl Unpin for Node

§

impl !UnwindSafe for Node

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.