Struct grote_opdracht::model::State
[−]
[src]
pub struct State {
pub current_score: Time,
pub events: [[Vec<Segment>; 5]; 2],
pub possible_orders: HashSet<u32>,
pub scheduled_orders: HashMap<u32, HashSet<(usize, usize, usize)>>,
pub orders: Arc<OrderList>,
pub travel_time: Arc<TravelTime>,
}Represents the searchable state in which we will try to minimize our score using local search algorithms. Operators come in two forms:
<operator>(), this will perform the operator like you'd expect.try_<operator>(), this function is called during the execution of the regular operator and returns the difference in score applying the operator would make and a list of instructions to be performed on the event lists.
The instructions returned by the try_<operator>() functions can be executed using the
execute_operator() function. See Action for more information.
Fields
current_score: Time
The total current score in time units.
events: [[Vec<Segment>; 5]; 2]
The events are structured as follows: state.events[truck][day][event_id].
Important
For efficiency reasons this list won't contain a final Events::Dump. All methods acting on
the state should still assume this event always happens!
possible_orders: HashSet<u32>
Which orders are still able to be scheduled.
scheduled_orders: HashMap<u32, HashSet<(usize, usize, usize)>>
In which vehicle, on which day and in which segment orders are scheduled. Needed for deletion.
orders: Arc<OrderList>
travel_time: Arc<TravelTime>
Methods
impl State[src]
pub fn new(orders: Arc<OrderList>, travel_time: Arc<TravelTime>) -> State[src]
Creates a new state, filling the list of possible orders using the supplied orderlist.
pub fn score(&self) -> f32[src]
Returns the current score in minutes.
pub fn execute_operator(&mut self, score_delta: Time, actions: &[Action])[src]
Performs the actions returned by the try_<operator>() functions.
Panics
This function does not perform any bounds checking, and will thus panic when invalid actions are passed.
pub fn insert_dump(&mut self, at: EventIndex) -> Result<(), StateError>[src]
Insert a dump at EventIndex. This will result in splitting the segment into two
segments.
pub fn try_insert_dump(
&self,
(vehicle, day, segment_id, split_index): EventIndex
) -> Result<(Time, Vec<Action>), StateError>[src]
&self,
(vehicle, day, segment_id, split_index): EventIndex
) -> Result<(Time, Vec<Action>), StateError>
Try to insert a dump at EventIndex by splitting the segment.
pub fn insert_order(
&mut self,
order_id: u32,
chosen_days: &[EventIndex]
) -> Result<(), StateError>[src]
&mut self,
order_id: u32,
chosen_days: &[EventIndex]
) -> Result<(), StateError>
Inserts an order into the schedule while preventing the order to be scheduled on
incompatible days. chosen_days should contain (vehicle, day, event_index) pairs on which
the order should be scheduled. If the truck would go over capacity a new dump gets inserted.
Inserting at event ID = day length will cause the order to be scheduled at the end of the
day.
pub fn try_insert_order(
&self,
order_id: u32,
chosen_days: &[EventIndex]
) -> Result<(Time, Vec<Action>), StateError>[src]
&self,
order_id: u32,
chosen_days: &[EventIndex]
) -> Result<(Time, Vec<Action>), StateError>
Calculate what would happen if an order were to be inserted. This returns the difference in score and for which days a dump should be added before the order.
pub fn insert_order_last(
&mut self,
order_id: u32,
chosen_days: &[(usize, usize)]
) -> Result<(), StateError>[src]
&mut self,
order_id: u32,
chosen_days: &[(usize, usize)]
) -> Result<(), StateError>
Inserts an order into the schedule at the end of the day. This function should only be used as a helper for creating the initial solutions.
pub fn try_insert_order_last(
&self,
order_id: u32,
chosen_days: &[(usize, usize)]
) -> Result<(Time, Vec<Action>), StateError>[src]
&self,
order_id: u32,
chosen_days: &[(usize, usize)]
) -> Result<(Time, Vec<Action>), StateError>
Simulates inserting an order into the schedule at the end of the day. This function should only be used as a helper for creating the initial solutions.
pub fn push_order(
&mut self,
from: EventIndex,
to: EventIndex
) -> Result<(), StateError>[src]
&mut self,
from: EventIndex,
to: EventIndex
) -> Result<(), StateError>
Moves an order from a vehicle/day/segment to another segment. This will return an error if the order doesn't fit in the new day due to volume or time constraints. The operator doesn't checker whether the order could actually be moved to the new day (due to frequency constraints).
pub fn try_push_order(
&self,
(from_vehicle, from_day, from_segment_id, from_index): EventIndex,
(to_vehicle, to_day, to_segment_id, to_index): EventIndex
) -> Result<(Time, Vec<Action>), StateError>[src]
&self,
(from_vehicle, from_day, from_segment_id, from_index): EventIndex,
(to_vehicle, to_day, to_segment_id, to_index): EventIndex
) -> Result<(Time, Vec<Action>), StateError>
Try to move an order from a vehicle/day/segment to another segment. See push_order for
more implementation details.
pub fn remove_order(&mut self, order_id: u32) -> Result<(), StateError>[src]
Removes an order from the schedule. Orders will be removed form all the days they are scheduled on. If this causes a segment to be empty it will get removed.
pub fn try_remove_order(
&self,
order_id: u32
) -> Result<(Time, Vec<Action>), StateError>[src]
&self,
order_id: u32
) -> Result<(Time, Vec<Action>), StateError>
Try to remove an order. An error will be returned if the order could not be removed. If this causes a segment to be empty it will get removed.
pub fn get_location_id(&self, order_id: Option<&u32>) -> u32[src]
Helper for finding the location id of an order, retrieved from self.events. If order is
None, this is either the location before the first or after the last order i.e. the
dumping location.
pub fn debug_recalculate_score(&self) -> f32[src]
Calculates what the score should have been in minutes. This is useful for debugging score fluctuations.
pub fn debug_validate(&self)[src]
Checks whether or not a solution is correct and feasible.
Trait Implementations
impl Clone for State[src]
fn clone(&self) -> State[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Debug for State[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more