Skip to content

Commit

Permalink
fixed ids in output bug; removed some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonSering committed Jul 12, 2024
1 parent 34a75b3 commit f3137a3
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 28,116 deletions.
27,888 changes: 0 additions & 27,888 deletions instances/kelheim-v3.0-25pct.scheduler_request_without_depots.json

This file was deleted.

5 changes: 0 additions & 5 deletions internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![allow(unused_imports)]
mod test_objective;

use im::HashMap;
use model::base_types::VehicleTypeIdx;
use model::vehicle_types::VehicleType;
use rapid_solve::heuristics::Solver;
use solution::transition::Transition;
use solver::local_search::neighborhood::swaps::SwapInfo;
Expand All @@ -25,7 +21,6 @@ use solver::min_cost_flow_solver::MinCostFlowSolver;
use solver::objective;

use model::json_serialisation::load_rolling_stock_problem_instance_from_json;
use solver::transition_cycle_tsp::TransitionCycleWithInfo;
use solver::transition_local_search::{build_transition_local_search_solver, TransitionWithInfo};

use std::sync::Arc;
Expand Down
197 changes: 0 additions & 197 deletions internal/src/test_objective.rs

This file was deleted.

2 changes: 1 addition & 1 deletion model/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl Network {
limit_of_type.map(|l| l.min(limit_of_node.unwrap_or(l)))
}

pub fn get_depot_id(&self, node_idx: NodeIdx) -> DepotIdx {
pub fn get_depot_idx(&self, node_idx: NodeIdx) -> DepotIdx {
self.node(node_idx).as_depot().depot_idx()
}

Expand Down
24 changes: 16 additions & 8 deletions solution/src/json_serialisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use model::{
base_types::{DepotIdx, NodeIdx, VehicleIdx, VehicleTypeIdx},
network::{nodes::Node, Network},
};
use serde::{Deserialize, Serialize};
use rapid_time::DateTime;
use serde::{Deserialize, Serialize};

use crate::Schedule;

Expand Down Expand Up @@ -144,9 +144,11 @@ pub fn schedule_to_json(schedule: &Schedule) -> serde_json::Value {

fn depots_usage_to_json(schedule: &Schedule) -> Vec<DepotLoad> {
let mut depot_loads = vec![];
for depot_idx in schedule.get_network().depots_iter() {
let network = schedule.get_network();
for depot_idx in network.depots_iter() {
let depot = network.get_depot(depot_idx);
depot_loads.push(DepotLoad {
depot: depot_idx.to_string(),
depot: depot.id().to_string(),
load: depot_usage_to_json(schedule, depot_idx),
});
}
Expand All @@ -155,12 +157,18 @@ fn depots_usage_to_json(schedule: &Schedule) -> Vec<DepotLoad> {

fn depot_usage_to_json(schedule: &Schedule, depot_idx: DepotIdx) -> Vec<Load> {
let mut loads = vec![];
let network = schedule.get_network();
for vehicle_type in schedule.get_vehicle_types().iter() {
let spawn_count =
schedule.number_of_vehicles_of_same_type_spawned_at(depot_idx, vehicle_type);
if spawn_count > 0 {
loads.push(Load {
vehicle_type: vehicle_type.to_string(),
vehicle_type: network
.vehicle_types()
.get(vehicle_type)
.unwrap()
.id()
.clone(),
spawn_count,
})
}
Expand All @@ -174,10 +182,10 @@ fn fleet_to_json(
dead_head_trips_with_formation: &mut Vec<JsonFleetDeadHeadTripWithFormation>,
) -> JsonFleet {
let mut vehicles = vec![];
for vehicle_id in schedule.vehicles_iter(vehicle_type) {
for vehicle_idx in schedule.vehicles_iter(vehicle_type) {
vehicles.push(vehicle_to_json(
schedule,
vehicle_id,
vehicle_idx,
dead_head_trips_with_formation,
));
}
Expand Down Expand Up @@ -210,10 +218,10 @@ fn vehicle_to_json(
) -> JsonVehicle {
let network = schedule.get_network();
let start_depot_node = schedule.tour_of(vehicle_idx).unwrap().first_node();
let start_depot_id = network.get_depot_id(start_depot_node);
let start_depot_id = network.get_depot_idx(start_depot_node);
let start_depot = network.get_depot(start_depot_id);
let end_depot_node = schedule.tour_of(vehicle_idx).unwrap().last_node();
let end_depot_id = network.get_depot_id(end_depot_node);
let end_depot_id = network.get_depot_idx(end_depot_node);
let end_depot = network.get_depot(end_depot_id);
let mut departure_segments = vec![];
let mut maintenance_slots = vec![];
Expand Down
10 changes: 5 additions & 5 deletions solution/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ impl Schedule {
// check depots usage
let vehicle_type = self.vehicle_type_of(*vehicle).unwrap();

let start_depot = self.network.get_depot_id(tour.start_depot().unwrap());
let start_depot = self.network.get_depot_idx(tour.start_depot().unwrap());
let (spawned, _) = self.depot_usage.get(&(start_depot, vehicle_type)).unwrap();
assert!(spawned.contains(vehicle));

let end_depot = self.network.get_depot_id(tour.end_depot().unwrap());
let end_depot = self.network.get_depot_idx(tour.end_depot().unwrap());
let (_, despawned) = self.depot_usage.get(&(end_depot, vehicle_type)).unwrap();
assert!(despawned.contains(vehicle));

Expand Down Expand Up @@ -492,7 +492,7 @@ impl Schedule {
assert_eq!(self.vehicle_type_of(*vehicle).unwrap(), *vehicle_type);
assert_eq!(
self.network
.get_depot_id(self.tour_of(*vehicle).unwrap().start_depot().unwrap()),
.get_depot_idx(self.tour_of(*vehicle).unwrap().start_depot().unwrap()),
*depot
);
}
Expand All @@ -501,7 +501,7 @@ impl Schedule {
assert_eq!(self.vehicle_type_of(*vehicle).unwrap(), *vehicle_type);
assert_eq!(
self.network
.get_depot_id(self.tour_of(*vehicle).unwrap().end_depot().unwrap()),
.get_depot_idx(self.tour_of(*vehicle).unwrap().end_depot().unwrap()),
*depot
);
}
Expand Down Expand Up @@ -714,7 +714,7 @@ impl Schedule {
vehicle_type: VehicleTypeIdx,
depot_usage: &DepotUsage,
) -> bool {
let depot = self.network.get_depot_id(start_depot);
let depot = self.network.get_depot_idx(start_depot);
let capacity_for_type = self.network.capacity_of(depot, vehicle_type);

if capacity_for_type == 0 {
Expand Down
Loading

0 comments on commit f3137a3

Please sign in to comment.