Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelist - gather coordinates for one to many routing #155

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4e43ce0
format
nilspenzel Sep 19, 2024
1dea051
wip
nilspenzel Sep 19, 2024
5976f36
wip
nilspenzel Sep 19, 2024
c8d720f
Merge branch 'master' into gather
nilspenzel Sep 19, 2024
4537cc3
wip
nilspenzel Sep 19, 2024
d326dc5
wip
nilspenzel Sep 20, 2024
55d93bf
wip
nilspenzel Sep 20, 2024
de81c52
wip
nilspenzel Sep 20, 2024
cb2ad94
Remove unsed functions
nilspenzel Sep 20, 2024
d103439
wip
nilspenzel Sep 20, 2024
549f4c0
wip
nilspenzel Sep 24, 2024
1607734
Format
nilspenzel Sep 24, 2024
59f08bf
wip
nilspenzel Sep 27, 2024
b0506dd
wip
nilspenzel Sep 27, 2024
0107310
wip
nilspenzel Sep 27, 2024
3dd888e
wip
nilspenzel Sep 29, 2024
6f77181
wip
nilspenzel Oct 8, 2024
a2e70a1
wip
nilspenzel Oct 8, 2024
ecbfbd9
wip
nilspenzel Oct 8, 2024
92fa21d
wip
nilspenzel Oct 8, 2024
83bd7ba
wip
nilspenzel Oct 8, 2024
acd1862
Rename CheckBookingValidityParameters -> WhiteListRequest
nilspenzel Oct 22, 2024
301e25a
Move busStopCompanyFilter into Company
nilspenzel Oct 22, 2024
c019ab1
Use alias type to clarify that type is used for vehicle ids
nilspenzel Oct 22, 2024
ca74dd8
wip
nilspenzel Oct 25, 2024
0cafb6f
Merge master
nilspenzel Nov 21, 2024
89eac37
Alter order of deleting columns in e2e tests
nilspenzel Nov 21, 2024
d5db993
Merge branch 'master' into gather
nilspenzel Nov 21, 2024
bc44522
wip
nilspenzel Dec 4, 2024
dc9ff45
wip
nilspenzel Dec 4, 2024
cfab605
wip
nilspenzel Dec 4, 2024
ac4a0b4
wip
nilspenzel Dec 4, 2024
7408408
wip
nilspenzel Dec 4, 2024
e50da66
wip
nilspenzel Dec 4, 2024
d262020
wip
nilspenzel Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/bookingApiParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BusStop } from './busStop';
import type { Capacities } from './capacities';
import type { Coordinates } from './location';

export type CheckBookingValidityParameters = {
export type WhiteListRequest = {
userChosen: Coordinates;
busStops: BusStop[];
startFixed: boolean;
Expand Down
28 changes: 28 additions & 0 deletions src/lib/compositionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,39 @@ import type { Capacities } from './capacities';
import type { Interval } from './interval';
import type { Coordinates } from './location';

export type Company = {
id: number;
coordinates: Coordinates;
vehicles: Vehicle[];
zoneId: number;
busStopFilter: boolean[];
};

export type Vehicle = {
id: number;
capacities: Capacities;
tours: Tour[];
events: Event[];
availabilities: Interval[];
lastEventBefore: Event | undefined;
firstEventAfter: Event | undefined;
};

export type Tour = {
arrival: Date;
departure: Date;
};

export type Event = {
capacities: Capacities;
is_pickup: boolean;
time: Interval;
id: number;
coordinates: Coordinates;
tourId: number;
arrival: Date;
departure: Date;
communicated: Date;
approachDuration: number;
returnDuration: number;
};
1 change: 1 addition & 0 deletions src/lib/typeAliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type VehicleId = number;
48 changes: 24 additions & 24 deletions src/routes/api/blacklisting/blacklisting.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CheckBookingValidityParameters } from '$lib/bookingApiParameters';
import type { WhiteListRequest as BlackListRequest } from '$lib/bookingApiParameters';
import { Coordinates } from '$lib/location';
import { describe, it, expect, beforeEach } from 'vitest';
import { getViableBusStops } from './viableBusStops';
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('blacklisting test', () => {
await setAvailability(taxi, dateInXMinutes(0), dateInXMinutes(90));
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(90));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -58,7 +58,7 @@ describe('blacklisting test', () => {

await setAvailability(taxi, dateInXMinutes(0), dateInXMinutes(90));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -75,7 +75,7 @@ describe('blacklisting test', () => {

await setTour(taxi, dateInXMinutes(0), dateInXMinutes(90));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -91,7 +91,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [
{ times: [dateInXMinutes(50), dateInXMinutes(10)], coordinates: inNiesky },
Expand All @@ -110,7 +110,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -126,7 +126,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inZittau }],
startFixed: true,
Expand All @@ -142,7 +142,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inZittau,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -158,7 +158,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -174,7 +174,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -190,7 +190,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -206,7 +206,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -219,7 +219,7 @@ describe('blacklisting test', () => {
it('blacklisting fail, no vehicle', async () => {
await addCompany(Zone.NIESKY);

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -230,7 +230,7 @@ describe('blacklisting test', () => {
});

it('blacklisting fail, no company', async () => {
const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -244,7 +244,7 @@ describe('blacklisting test', () => {
const capacities: Capacities = { passengers: 3, bikes: 3, wheelchairs: 3, luggage: 3 };
const company = await addCompany(Zone.NIESKY);
await addTaxi(company, capacities);
const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -260,7 +260,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [
{ times: [dateInXMinutes(50)], coordinates: inZittau },
Expand All @@ -281,7 +281,7 @@ describe('blacklisting test', () => {
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [dateInXMinutes(1000), dateInXMinutes(50)], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -294,7 +294,7 @@ describe('blacklisting test', () => {
});

it('blacklisting, no busStops', async () => {
const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [],
startFixed: true,
Expand All @@ -309,7 +309,7 @@ describe('blacklisting test', () => {
const company = await addCompany(Zone.NIESKY);
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));
const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [
{ times: [], coordinates: inNiesky },
Expand All @@ -329,7 +329,7 @@ describe('blacklisting test', () => {
const company = await addCompany(Zone.NIESKY);
const taxi = await addTaxi(company, capacities);
await setTour(taxi, dateInXMinutes(0), dateInXMinutes(900));
const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [{ times: [], coordinates: inNiesky }],
startFixed: true,
Expand All @@ -346,7 +346,7 @@ describe('blacklisting test', () => {

await setAvailability(taxi, dateInXMinutes(0), dateInXMinutes(90));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [
{
Expand All @@ -368,7 +368,7 @@ describe('blacklisting test', () => {

await setAvailability(taxi, dateInXMinutes(0), dateInXMinutes(90));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [
{
Expand All @@ -390,7 +390,7 @@ describe('blacklisting test', () => {

await setAvailability(taxi, dateInXMinutes(0), dateInXMinutes(90));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [
{ times: [dateInXMinutesYMs(0, -MAX_PASSENGER_WAITING_TIME_PICKUP)], coordinates: inNiesky }
Expand All @@ -409,7 +409,7 @@ describe('blacklisting test', () => {

await setAvailability(taxi, dateInXMinutes(0), dateInXMinutes(90));

const r: CheckBookingValidityParameters = {
const r: BlackListRequest = {
userChosen: inNiesky,
busStops: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/blacklisting/viableBusStops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const getViableBusStops = async (
busStops: BusStop[],
startFixed: boolean,
capacities: Capacities
): Promise<BlacklistingResult[]> => {
): Promise<BlacklistingResponse[]> => {
if (busStops.length == 0 || !busStops.some((b) => b.times.length != 0)) {
return [];
}
Expand Down Expand Up @@ -160,7 +160,7 @@ export const getViableBusStops = async (
return dbResult;
};

type BlacklistingResult = {
type BlacklistingResponse = {
timeIndex: number;
busstopindex: number;
};
7 changes: 6 additions & 1 deletion src/routes/api/whitelist/capacitySimulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ function createEventCapacitiesOnly(capacities: Capacities, is_pickup: boolean):
time: new Interval(now, now),
id: 1,
coordinates: new Coordinates(1, 1),
tourId: 1
tourId: 1,
arrival: new Date(),
departure: new Date(),
communicated: new Date(),
approachDuration: 0,
returnDuration: 0
};
}

Expand Down
11 changes: 11 additions & 0 deletions src/routes/api/whitelist/insertionTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Vehicle } from '$lib/compositionTypes';
import type { Range } from './capacitySimulation';

export type InsertionInfo = {
companyIdx: number;
prevEventIdxInRoutingResults: number;
nextEventIdxInRoutingResults: number;
vehicle: Vehicle;
idxInEvents: number;
currentRange: Range;
};
80 changes: 80 additions & 0 deletions src/routes/api/whitelist/routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { oneToMany } from '$lib/api';
import type { BusStop } from '$lib/busStop';
import type { Company } from '$lib/compositionTypes';
import { Coordinates } from '$lib/location';
import type { VehicleId } from '$lib/typeAliases';
import type { Range } from './capacitySimulation';
import { iterateAllInsertions } from './utils';

export type InsertionRoutingResult = {
company: number[];
event: number[];
};

export type RoutingResults = {
busStops: InsertionRoutingResult[];
userChosen: InsertionRoutingResult;
};

export function gatherRoutingCoordinates(
companies: Company[],
insertionsByVehicle: Map<VehicleId, Range[]>
) {
if (companies.length == 0) {
return { forward: [], backward: [] };
}
const backward = new Array<Coordinates>();
const forward = new Array<Coordinates>();
companies.forEach((company) => {
forward.push(company.coordinates);
backward.push(company.coordinates);
});
iterateAllInsertions(companies, insertionsByVehicle, (insertionInfo, _insertionCounter) => {
const vehicle = insertionInfo.vehicle;
const idxInEvents = insertionInfo.idxInEvents;
if (idxInEvents != 0) {
backward.push(vehicle.events[idxInEvents - 1].coordinates);
} else if (vehicle.lastEventBefore != undefined) {
backward.push(vehicle.lastEventBefore.coordinates);
}
if (idxInEvents != vehicle.events.length) {
forward.push(vehicle.events[idxInEvents].coordinates);
} else if (vehicle.firstEventAfter != undefined) {
forward.push(vehicle.firstEventAfter.coordinates);
}
});
return { forward, backward };
}

export async function routing(
companies: Company[],
many: { forward: Coordinates[]; backward: Coordinates[] },
userChosen: Coordinates,
busStops: BusStop[],
startFixed: boolean
): Promise<RoutingResults> {
const userChosenResult = await oneToMany(
userChosen,
startFixed ? many.backward : many.forward,
!startFixed
);
const ret = {
userChosen: {
company: userChosenResult.slice(0, companies.length),
event: userChosenResult.slice(companies.length)
},
busStops: new Array<InsertionRoutingResult>(busStops.length)
};
for (let busStopIdx = 0; busStopIdx != busStops.length; ++busStopIdx) {
const busStopResult = await oneToMany(
busStops[busStopIdx].coordinates,
!startFixed ? many.backward : many.forward,
startFixed
);
ret.busStops[busStopIdx] = {
company: busStopResult.slice(0, companies.length),
event: busStopResult.slice(companies.length)
};
}
return ret;
}
Loading