Skip to content

Commit 2acd683

Browse files
authored
Merge pull request #3772 from moia-oss/shiftTypes
DRT shifts: add shift type
2 parents cecdd5c + 753a894 commit 2acd683

File tree

16 files changed

+235
-35
lines changed

16 files changed

+235
-35
lines changed

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/AssignShiftToVehicleLogic.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
/*
2-
* Copyright (C) 2022 MOIA GmbH - All Rights Reserved
3-
*
4-
* You may use, distribute and modify this code under the terms
5-
* of the GNU General Public License as published by
6-
* the Free Software Foundation; either version 2 of the License,
7-
* or (at your option) any later version.
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
819
*/
920
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
1021

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DefaultAssignShiftToVehicleLogic.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
/*
2-
* Copyright (C) 2022 MOIA GmbH - All Rights Reserved
3-
*
4-
* You may use, distribute and modify this code under the terms
5-
* of the GNU General Public License as published by
6-
* the Free Software Foundation; either version 2 of the License,
7-
* or (at your option) any later version.
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
819
*/
920
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
1021

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DefaultShiftScheduler.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
19+
*/
120
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
221

322
import com.google.common.collect.ImmutableMap;
@@ -26,7 +45,7 @@ public final class DefaultShiftScheduler implements ShiftScheduler {
2645
}
2746
return (DrtShift) new DrtShiftImpl(spec.getId(), spec.getStartTime(), spec.getEndTime(),
2847
spec.getOperationFacilityId().orElse(null), spec.getDesignatedVehicleId().orElse(null),
29-
shiftBreak);
48+
shiftBreak, spec.getShiftType().orElse(null));
3049
};
3150

3251
public DefaultShiftScheduler(DrtShiftsSpecification shiftsSpecification) {

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DefaultShiftStartLogic.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
/*
2-
* Copyright (C) 2022 MOIA GmbH - All Rights Reserved
3-
*
4-
* You may use, distribute and modify this code under the terms
5-
* of the GNU General Public License as published by
6-
* the Free Software Foundation; either version 2 of the License,
7-
* or (at your option) any later version.
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
819
*/
920
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
1021

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DrtShiftDispatcher.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
19+
*/
120
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
221

322
import org.matsim.api.core.v01.Id;

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DrtShiftDispatcherImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
19+
*/
120
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
221

322
import com.google.common.base.Verify;

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/ShiftScheduler.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
19+
*/
120
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
221

322
import com.google.common.collect.ImmutableMap;

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/ShiftStartLogic.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
/*
2-
* Copyright (C) 2022 MOIA GmbH - All Rights Reserved
3-
*
4-
* You may use, distribute and modify this code under the terms
5-
* of the GNU General Public License as published by
6-
* the Free Software Foundation; either version 2 of the License,
7-
* or (at your option) any later version.
2+
* *********************************************************************** *
3+
* project: org.matsim.*
4+
* *********************************************************************** *
5+
* *
6+
* copyright : (C) 2025 by the members listed in the COPYING, *
7+
* LICENSE and WARRANTY file. *
8+
* email : info at matsim dot org *
9+
* *
10+
* *********************************************************************** *
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* See also COPYING, LICENSE and WARRANTY file *
17+
* *
18+
* *********************************************************************** *
819
*/
920
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;
1021

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/io/DrtShiftsReader.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ public class DrtShiftsReader extends MatsimXmlParser {
2525
private final static String BREAK_NAME = "break";
2626

2727
public static final String ID = "id";
28+
2829
public static final String START_TIME = "start";
2930
public static final String END_TIME = "end";
31+
3032
public static final String OPERATION_FACILITY_ID = "operationFacilityId";
3133
public static final String DESIGNATED_VEHICLE_ID = "designatedVehicleId";
3234

3335
public static final String EARLIEST_BREAK_START_TIME = "earliestStart";
3436
public static final String LATEST_BREAK_END_TIME = "latestEnd";
3537
public static final String BREAK_DURATION = "duration";
3638

39+
public static final String TYPE = "type";
40+
3741
private static final Logger log = LogManager.getLogger( DrtShiftsReader.class ) ;
3842

3943
private final DrtShiftsSpecification shiftsSpecification;
@@ -63,6 +67,10 @@ public void startTag(final String name, final Attributes atts, final Stack<Strin
6367
if(designatedVehicleId != null) {
6468
builder.designatedVehicle(Id.create(designatedVehicleId, DvrpVehicle.class));
6569
}
70+
String type = atts.getValue(TYPE);
71+
if(type != null) {
72+
builder.type(type);
73+
}
6674
currentBuilder = builder;
6775
break;
6876
case BREAK_NAME:

contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/io/DrtShiftsWriter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ public class DrtShiftsWriter extends MatsimXmlWriter {
2828
private final static String BREAK_NAME = "break";
2929

3030
public static final String ID = "id";
31+
3132
public static final String START_TIME = "start";
3233
public static final String END_TIME = "end";
34+
3335
public static final String OPERATION_FACILITY_ID = "operationFacilityId";
3436
public static final String DESIGNATED_VEHICLE_ID = "designatedVehicleId";
3537

3638
public static final String EARLIEST_BREAK_START_TIME = "earliestStart";
3739
public static final String LATEST_BREAK_END_TIME = "latestEnd";
3840
public static final String BREAK_DURATION = "duration";
3941

42+
public static final String TYPE = "type";
43+
4044
private static final Logger log = LogManager.getLogger(DrtShiftsWriter.class);
4145

4246
private final Map<Id<DrtShift>, DrtShiftSpecification> shifts;
@@ -64,7 +68,7 @@ private void writeShifts(Map<Id<DrtShift>, DrtShiftSpecification> shifts) throws
6468
List<DrtShiftSpecification> sortedShifts = shifts.values()
6569
.stream()
6670
.sorted(Comparator.comparing(Identifiable::getId))
67-
.collect(Collectors.toList());
71+
.toList();
6872
for (DrtShiftSpecification shift : sortedShifts) {
6973
atts.clear();
7074
atts.add(createTuple(ID, shift.getId().toString()));
@@ -74,6 +78,8 @@ private void writeShifts(Map<Id<DrtShift>, DrtShiftSpecification> shifts) throws
7478
atts.add(createTuple(OPERATION_FACILITY_ID, operationFacilityId.toString())));
7579
shift.getDesignatedVehicleId().ifPresent(designatedVehicleId ->
7680
atts.add(createTuple(DESIGNATED_VEHICLE_ID, designatedVehicleId.toString())));
81+
shift.getShiftType().ifPresent(shiftType ->
82+
atts.add(createTuple(TYPE, shiftType)));
7783
this.writeStartTag(SHIFT_NAME, atts);
7884

7985
//Write break, if present

0 commit comments

Comments
 (0)