@@ -251,7 +251,7 @@ public static void readAndCreateCarrierFromCSV(Scenario scenario, FreightCarrier
251
251
checkNewCarrier (allNewCarrierInformation , freightCarriersConfigGroup , scenario , indexShape , shapeCategory );
252
252
log .info ("The read carrier information from the csv are checked without errors." );
253
253
createNewCarrierAndAddVehicleTypes (scenario , allNewCarrierInformation , freightCarriersConfigGroup , indexShape ,
254
- defaultJspritIterations , crsTransformationNetworkAndShape );
254
+ defaultJspritIterations , crsTransformationNetworkAndShape );
255
255
}
256
256
257
257
/**
@@ -263,33 +263,33 @@ static Set<CarrierInformationElement> readCarrierInformation(Path csvLocationCar
263
263
log .info ("Start reading carrier csv file: {}" , csvLocationCarrier );
264
264
Set <CarrierInformationElement > allNewCarrierInformation = new HashSet <>();
265
265
CSVParser parse = new CSVParser (Files .newBufferedReader (csvLocationCarrier ),
266
- CSVFormat .Builder .create (CSVFormat .TDF ).setHeader ().setSkipHeaderRecord (true ).build ());
266
+ CSVFormat .Builder .create (CSVFormat .TDF ).setHeader ().setSkipHeaderRecord (true ).build ());
267
267
for (CSVRecord record : parse ) {
268
268
CarrierInformationElement .Builder builder ;
269
269
if (!record .get ("carrierName" ).isBlank ())
270
270
builder = CarrierInformationElement .Builder .newInstance (record .get ("carrierName" ));
271
271
else
272
272
throw new RuntimeException (
273
- "Minimum one carrier has no name. Every carrier information has to be related to one carrier. Please check the input csv file!" );
273
+ "Minimum one carrier has no name. Every carrier information has to be related to one carrier. Please check the input csv file!" );
274
274
if (!record .get ("vehicleTypes" ).isBlank ())
275
275
builder .setVehicleTypes (record .get ("vehicleTypes" ).split (";" ));
276
276
if (!record .get ("numberOfDepots" ).isBlank ())
277
277
builder .setNumberOfDepotsPerType (Integer .parseInt (record .get ("numberOfDepots" )));
278
278
if (!record .get ("selectedVehicleDepots" ).isBlank ())
279
279
builder .setVehicleDepots (
280
- new ArrayList <String >(Arrays .asList (record .get ("selectedVehicleDepots" ).split (";" ))));
280
+ new ArrayList <>(Arrays .asList (record .get ("selectedVehicleDepots" ).split (";" ))));
281
281
if (!record .get ("areaOfAdditionalDepots" ).isBlank ())
282
282
builder .setAreaOfAdditionalDepots (record .get ("areaOfAdditionalDepots" ).split (";" ));
283
283
if (!record .get ("fixedNumberOfVehiclePerTypeAndLocation" ).isBlank ())
284
284
builder .setFixedNumberOfVehiclePerTypeAndLocation (
285
- Integer .parseInt (record .get ("fixedNumberOfVehiclePerTypeAndLocation" )));
285
+ Integer .parseInt (record .get ("fixedNumberOfVehiclePerTypeAndLocation" )));
286
286
if (!record .get ("fleetSize" ).isBlank () && record .get ("fleetSize" ).contentEquals ("infinite" ))
287
287
builder .setFleetSize (FleetSize .INFINITE );
288
288
else if (!record .get ("fleetSize" ).isBlank () && record .get ("fleetSize" ).contentEquals ("finite" ))
289
289
builder .setFleetSize (FleetSize .FINITE );
290
290
else if (!record .get ("fleetSize" ).isBlank ())
291
291
throw new RuntimeException ("Select a valid FleetSize for the carrier: " + builder .getCarrierName ()
292
- + ". Possible is finite or infinite!!" );
292
+ + ". Possible is finite or infinite!!" );
293
293
if (!record .get ("vehicleStartTime" ).isBlank ())
294
294
builder .setVehicleStartTime (Integer .parseInt (record .get ("vehicleStartTime" )));
295
295
if (!record .get ("vehicleEndTime" ).isBlank ())
@@ -317,45 +317,44 @@ static void checkNewCarrier(Set<CarrierInformationElement> allNewCarrierInformat
317
317
CarriersUtils .addOrGetCarriers (scenario );
318
318
for (CarrierInformationElement carrierElement : allNewCarrierInformation ) {
319
319
if (CarriersUtils .getCarriers (scenario ).getCarriers ()
320
- .containsKey (Id .create (carrierElement .getName (), Carrier .class )))
320
+ .containsKey (Id .create (carrierElement .getName (), Carrier .class )))
321
321
throw new RuntimeException ("The Carrier " + carrierElement .getName ()
322
- + " being loaded from the csv is already in the given Carrier file. It is not possible to add to an existing Carrier. Please check!" );
322
+ + " being loaded from the csv is already in the given Carrier file. It is not possible to add to an existing Carrier. Please check!" );
323
323
CarrierVehicleTypes carrierVehicleTypes = new CarrierVehicleTypes ();
324
324
new CarrierVehicleTypeReader (carrierVehicleTypes )
325
- .readFile (freightCarriersConfigGroup .getCarriersVehicleTypesFile ());
325
+ .readFile (freightCarriersConfigGroup .getCarriersVehicleTypesFile ());
326
326
if (carrierElement .getVehicleTypes () != null )
327
327
for (String type : carrierElement .getVehicleTypes ()) {
328
328
if (!carrierVehicleTypes .getVehicleTypes ().containsKey (Id .create (type , VehicleType .class )))
329
329
throw new RuntimeException ("The selected vehicleType " + type + " of the carrier "
330
- + carrierElement .getName ()
331
- + " in the input file is not part of imported vehicle types. Please change the type or add the type in the vehicleTypes input file!" );
330
+ + carrierElement .getName ()
331
+ + " in the input file is not part of imported vehicle types. Please change the type or add the type in the vehicleTypes input file!" );
332
332
}
333
333
if (carrierElement .getVehicleDepots () != null ) {
334
334
if (carrierElement .getNumberOfDepotsPerType () < carrierElement .getVehicleDepots ().size ())
335
335
throw new RuntimeException ("For the carrier " + carrierElement .getName ()
336
- + " more certain depots than the given number of depots are selected. (numberOfDepots < selectedVehicleDepots)" );
336
+ + " more certain depots than the given number of depots are selected. (numberOfDepots < selectedVehicleDepots)" );
337
337
338
338
for (String linkDepot : carrierElement .getVehicleDepots ()) {
339
339
if (!scenario .getNetwork ().getLinks ().containsKey (Id .create (linkDepot , Link .class )))
340
340
throw new RuntimeException ("The selected link " + linkDepot + " for a depot of the carrier "
341
- + carrierElement .getName () + " is not part of the network. Please check!" );
341
+ + carrierElement .getName () + " is not part of the network. Please check!" );
342
342
}
343
343
}
344
344
if (carrierElement .getVehicleTypes () != null && carrierElement .getNumberOfDepotsPerType () == 0
345
- && carrierElement .getVehicleDepots () == null )
345
+ && carrierElement .getVehicleDepots () == null )
346
346
throw new RuntimeException (
347
- "If a vehicle type is selected in the input file, numberOfDepots or selectedVehicleDepots should be set. Please check carrier "
348
- + carrierElement .getName ());
347
+ "If a vehicle type is selected in the input file, numberOfDepots or selectedVehicleDepots should be set. Please check carrier "
348
+ + carrierElement .getName ());
349
349
if ((carrierElement .getVehicleDepots () != null
350
350
&& (carrierElement .getNumberOfDepotsPerType () > carrierElement .getVehicleDepots ().size ())
351
351
&& carrierElement .getAreaOfAdditionalDepots () == null ) || (carrierElement .getVehicleDepots () == null && (carrierElement .getNumberOfDepotsPerType () > 0 )
352
352
&& carrierElement .getAreaOfAdditionalDepots () == null ))
353
- log .warn (
354
- "No possible area for additional depot given. Random choice in the hole network of a possible position" );
353
+ log .warn ("No possible area for additional depot given. Random choice in the hole network of a possible position" );
355
354
if (carrierElement .getAreaOfAdditionalDepots () != null ) {
356
355
if (indexShape == null )
357
356
throw new RuntimeException ("For carrier " + carrierElement .getName ()
358
- + " a certain area for depots is selected, but no shape is read in. Please check." );
357
+ + " a certain area for depots is selected, but no shape is read in. Please check." );
359
358
for (String depotArea : carrierElement .getAreaOfAdditionalDepots ()) {
360
359
boolean isInShape = false ;
361
360
for (SimpleFeature singlePolygon : indexShape .getShp ().readFeatures ()) {
@@ -366,38 +365,38 @@ static void checkNewCarrier(Set<CarrierInformationElement> allNewCarrierInformat
366
365
}
367
366
if (!isInShape )
368
367
throw new RuntimeException ("The area " + depotArea + " of the possible depots of carrier"
369
- + carrierElement .getName () + " is not part of the given shapeFile. The areas should be in the shape file column " + shapeCategory );
368
+ + carrierElement .getName () + " is not part of the given shapeFile. The areas should be in the shape file column " + shapeCategory );
370
369
}
371
370
}
372
371
if (carrierElement .getFixedNumberOfVehiclePerTypeAndLocation () != 0 )
373
372
for (CarrierInformationElement existingCarrier : allNewCarrierInformation )
374
373
if ((existingCarrier .getName ().equals (carrierElement .getName ())
375
- && existingCarrier .getFleetSize () == FleetSize .INFINITE )
376
- || carrierElement .getFleetSize () == FleetSize .INFINITE )
374
+ && existingCarrier .getFleetSize () == FleetSize .INFINITE )
375
+ || carrierElement .getFleetSize () == FleetSize .INFINITE )
377
376
throw new RuntimeException ("For the carrier " + carrierElement .getName ()
378
- + " a infinite fleetSize configuration was set, although you want to set a fixed number of vehicles. Please check!" );
377
+ + " a infinite fleetSize configuration was set, although you want to set a fixed number of vehicles. Please check!" );
379
378
if (carrierElement .getFleetSize () != null )
380
379
for (CarrierInformationElement existingCarrier : allNewCarrierInformation )
381
380
if (existingCarrier .getName ().equals (carrierElement .getName ())
382
- && existingCarrier .getFleetSize () != null
383
- && existingCarrier .getFleetSize () != carrierElement .getFleetSize ())
381
+ && existingCarrier .getFleetSize () != null
382
+ && existingCarrier .getFleetSize () != carrierElement .getFleetSize ())
384
383
throw new RuntimeException ("For the carrier " + carrierElement .getName ()
385
- + " different fleetSize configuration was set. Please check and select only one!" );
384
+ + " different fleetSize configuration was set. Please check and select only one!" );
386
385
if (carrierElement .getVehicleTypes () != null ) {
387
386
if (carrierElement .getVehicleStartTime () == 0 || carrierElement .getVehicleEndTime () == 0 )
388
387
throw new RuntimeException ("For the vehicle types of the carrier " + carrierElement .getName ()
389
- + " no start and/or end time for the vehicles was selected. Please set both times!!" );
388
+ + " no start and/or end time for the vehicles was selected. Please set both times!!" );
390
389
if (carrierElement .getVehicleStartTime () >= carrierElement .getVehicleEndTime ())
391
390
throw new RuntimeException ("For the vehicle types of the carrier " + carrierElement .getName ()
392
- + " a startTime after the endTime for the vehicles was selected. Please check!" );
391
+ + " a startTime after the endTime for the vehicles was selected. Please check!" );
393
392
}
394
393
if (carrierElement .getJspritIterations () != 0 )
395
394
for (CarrierInformationElement existingCarrier : allNewCarrierInformation )
396
395
if (existingCarrier .getName ().equals (carrierElement .getName ())
397
- && existingCarrier .getJspritIterations () != 0
398
- && existingCarrier .getJspritIterations () != carrierElement .getJspritIterations ())
396
+ && existingCarrier .getJspritIterations () != 0
397
+ && existingCarrier .getJspritIterations () != carrierElement .getJspritIterations ())
399
398
throw new RuntimeException ("For the carrier " + carrierElement .getName ()
400
- + " different number of jsprit iterations are set. Please check!" );
399
+ + " different number of jsprit iterations are set. Please check!" );
401
400
}
402
401
}
403
402
@@ -439,51 +438,51 @@ static void createNewCarrierAndAddVehicleTypes(Scenario scenario,
439
438
if (singleNewCarrier .getJspritIterations () > 0 )
440
439
CarriersUtils .setJspritIterations (thisCarrier , singleNewCarrier .getJspritIterations ());
441
440
carrierCapabilities = CarrierCapabilities .Builder .newInstance ()
442
- .setFleetSize (singleNewCarrier .getFleetSize ()).build ();
441
+ .setFleetSize (singleNewCarrier .getFleetSize ()).build ();
443
442
carriers .addCarrier (thisCarrier );
444
443
}
445
444
if (singleNewCarrier .getVehicleDepots () == null )
446
- singleNewCarrier .setVehicleDepots (new ArrayList <String >());
445
+ singleNewCarrier .setVehicleDepots (new ArrayList <>());
447
446
Random rand = new Random (singleNewCarrier .getName ().hashCode ());
448
447
int cnt = 0 ;
449
448
while (singleNewCarrier .getVehicleDepots ().size () < singleNewCarrier .getNumberOfDepotsPerType ()) {
450
449
Link link = scenario .getNetwork ().getLinks ().values ().stream ()
451
- .skip (rand .nextInt (scenario .getNetwork ().getLinks ().size ())).findAny ().get ();
450
+ .skip (rand .nextInt (scenario .getNetwork ().getLinks ().size ())).findAny ().get ();
452
451
cnt ++;
453
452
if ((!singleNewCarrier .getVehicleDepots ().contains (link .getId ().toString ())
454
- || cnt > scenario .getNetwork ().getLinks ().size ())
455
- && !link .getId ().toString ().contains ("pt" )
456
- && (!link .getAttributes ().getAsMap ().containsKey ("type" )
457
- || !link .getAttributes ().getAsMap ().get ("type" ).toString ().contains ("motorway" ))
458
- && FreightDemandGenerationUtils .checkPositionInShape (link , null , indexShape ,
459
- singleNewCarrier .getAreaOfAdditionalDepots (), crsTransformationNetworkAndShape )) {
453
+ || cnt > scenario .getNetwork ().getLinks ().size ())
454
+ && !link .getId ().toString ().contains ("pt" )
455
+ && (!link .getAttributes ().getAsMap ().containsKey ("type" )
456
+ || !link .getAttributes ().getAsMap ().get ("type" ).toString ().contains ("motorway" ))
457
+ && FreightDemandGenerationUtils .checkPositionInShape (link , null , indexShape ,
458
+ singleNewCarrier .getAreaOfAdditionalDepots (), crsTransformationNetworkAndShape )) {
460
459
singleNewCarrier .getVehicleDepots ().add (link .getId ().toString ());
461
460
}
462
461
}
463
462
for (String singleDepot : singleNewCarrier .getVehicleDepots ()) {
464
463
int countDepots = 2 ;
465
464
for (String thisVehicleType : singleNewCarrier .getVehicleTypes ()) {
466
465
VehicleType thisType = carrierVehicleTypes .getVehicleTypes ()
467
- .get (Id .create (thisVehicleType , VehicleType .class ));
466
+ .get (Id .create (thisVehicleType , VehicleType .class ));
468
467
usedCarrierVehicleTypes .getVehicleTypes ().putIfAbsent (Id .create (thisVehicleType , VehicleType .class ),
469
- thisType );
468
+ thisType );
470
469
if (singleNewCarrier .getFixedNumberOfVehiclePerTypeAndLocation () == 0 )
471
470
singleNewCarrier .setFixedNumberOfVehiclePerTypeAndLocation (1 );
472
471
for (int i = 0 ; i < singleNewCarrier .getFixedNumberOfVehiclePerTypeAndLocation (); i ++) {
473
472
Id <Vehicle > vehilcelId = Id .create (
474
- thisType .getId ().toString () + "_" + thisCarrier .getId ().toString () + "_" + singleDepot
475
- + "_start" + singleNewCarrier .getVehicleStartTime () + "_" + (i + 1 ),
476
- Vehicle .class );
473
+ thisType .getId ().toString () + "_" + thisCarrier .getId ().toString () + "_" + singleDepot
474
+ + "_start" + singleNewCarrier .getVehicleStartTime () + "_" + (i + 1 ),
475
+ Vehicle .class );
477
476
while (carrierCapabilities .getCarrierVehicles ().containsKey (vehilcelId )) {
478
477
vehilcelId = Id .create (thisType .getId ().toString () + "_" + thisCarrier .getId ().toString ()
479
- + "_" + singleDepot + "_V" + countDepots + "_start"
480
- + singleNewCarrier .getVehicleStartTime () + "_" + (i + 1 ), Vehicle .class );
478
+ + "_" + singleDepot + "_V" + countDepots + "_start"
479
+ + singleNewCarrier .getVehicleStartTime () + "_" + (i + 1 ), Vehicle .class );
481
480
countDepots ++;
482
481
}
483
482
CarrierVehicle newCarrierVehicle = CarrierVehicle .Builder
484
- .newInstance (vehilcelId , Id .createLinkId (singleDepot ), thisType )
485
- .setEarliestStart (singleNewCarrier .getVehicleStartTime ())
486
- .setLatestEnd (singleNewCarrier .getVehicleEndTime ()).build ();
483
+ .newInstance (vehilcelId , Id .createLinkId (singleDepot ), thisType )
484
+ .setEarliestStart (singleNewCarrier .getVehicleStartTime ())
485
+ .setLatestEnd (singleNewCarrier .getVehicleEndTime ()).build ();
487
486
carrierCapabilities .getCarrierVehicles ().put (newCarrierVehicle .getId (), newCarrierVehicle );
488
487
if (!carrierCapabilities .getVehicleTypes ().contains (thisType ))
489
488
carrierCapabilities .getVehicleTypes ().add (thisType );
0 commit comments