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
impl Node
Sourcepub const fn eos(
preceding_step: usize,
preceding_edge_costs: Rc<Vec<i32>>,
best_preceding_node: usize,
path_cost: i32,
) -> Self
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.
Sourcepub 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
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.
Sourcepub 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>
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>
Sourcepub fn value(&self) -> Option<&dyn Any>
pub fn value(&self) -> Option<&dyn Any>
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}
Sourcepub const fn index_in_step(&self) -> usize
pub const fn index_in_step(&self) -> usize
Sourcepub const fn preceding_step(&self) -> usize
pub const fn preceding_step(&self) -> usize
Sourcepub fn preceding_edge_costs(&self) -> &Vec<i32>
pub fn preceding_edge_costs(&self) -> &Vec<i32>
Sourcepub const fn best_preceding_node(&self) -> usize
pub const fn best_preceding_node(&self) -> usize
Trait Implementations§
impl Eq for Node
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> 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