Skip to content

Commit

Permalink
To designate #1, #2, etc safest paths in SafeStore
Browse files Browse the repository at this point in the history
  • Loading branch information
alicia-lyu committed Aug 17, 2023
1 parent e654bbb commit 6ac205f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ export class RouteStoreCleared implements Action {}

export class RouteStoreLoaded implements Action {
readonly newPaths: Path[]
constructor(newPaths: Path[]) {
readonly middlePointsAdded: boolean
constructor(newPaths: Path[], middlePointsAdded: boolean) {
this.newPaths = newPaths
this.middlePointsAdded = middlePointsAdded
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/stores/RouteStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class RouteStore extends Store<RouteStoreState> {
};
restoredPaths.push(restoredPath);
}
Dispatcher.dispatch(new RouteStoreLoaded(restoredPaths))
Dispatcher.dispatch(new RouteStoreLoaded(restoredPaths, true))
return {
routingResult: {
...state.routingResult,
Expand All @@ -137,7 +137,7 @@ export default class RouteStore extends Store<RouteStoreState> {
newPaths.push(path)
}
})
Dispatcher.dispatch(new RouteStoreLoaded(newPaths))
Dispatcher.dispatch(new RouteStoreLoaded(newPaths, false))
return {
routingResult: {
...state.routingResult,
Expand Down
37 changes: 32 additions & 5 deletions src/stores/SafetyStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { RouteStoreCleared, RouteStoreLoaded } from "@/actions/Actions";
import { IndexStoreState, SegmentWithIndex } from ".";
import RouteStore from "./RouteStore";
import Store from "./Store";
import { Path } from "@/api/graphhopper";
import { Path, RoutingArgs } from "@/api/graphhopper";
import { calcGaussianRandom } from './utils'
import QueryStore from "./QueryStore";


export default class SafetyStore extends Store<IndexStoreState> {
readonly routeStore: RouteStore
readonly queryStore: QueryStore
// We use queryStore to designate the default safest path:
// the first path in this.routeStore.state.routingResult.paths which has middlePoints added.
// We use queryStore to designate the default #1, #2, #3 safest paths
// #2: the first path in this.routeStore.state.routingResult.paths which has no middlePoints added.
// #3: the second path in this.routeStore.state.routingResult.paths which has middlePoints added.
private static indexStoreState: IndexStoreState = { paths: [] }


Expand All @@ -38,6 +39,28 @@ export default class SafetyStore extends Store<IndexStoreState> {
return state;
}
}

// #1 safest path: the first member in this.routeStore.state.routingResult.paths which has middlePoints added.
private static getTheSafestPath(paths: Path[], middlePointsAdded: boolean): Path {
// TODO (Jingwen): implement this method
// To look up whether middlePoints are added
//
throw new Error("Method not implemented.");
}

// #2 safest path: the first member in this.routeStore.state.routingResult.paths which has no middlePoints added.
private static getTheSecondSafestPath(paths: Path[], middlePointsAdded: boolean): Path {
// TODO (Jingwen): implement this method
throw new Error("Method not implemented.");
}

// #3 safest path: all the rest members in this.routeStore.state.routingResult.paths.
private static getTheThirdSafestPath(paths: Path[], middlePointsAdded: boolean): Path {
// TODO (Jingwen): implement this method
throw new Error("Method not implemented.");
}


/**
* Generate safety index for paths newly added to route store
* while reserving safety index for paths already in route store.
Expand All @@ -49,8 +72,11 @@ export default class SafetyStore extends Store<IndexStoreState> {
* @returns the new state of SafetyStore
*/
private static generateSafetyForPaths(newPaths: Path[]): IndexStoreState {
// TODO (Jingwen)
// For normal distribution, use calcGaussianRandom in ./utils.ts
// TODO (Jingwen): edit this method to use the updated data structure of IndexStoreState
// Edit this method to use different normal distribution to generate safety index for #1, #2, #3 safest paths
// #1: mean 4.5, std 1
// #2: mean 3.5, std 1
// #3 and beyond: mean 2.5, std 1
newPaths.forEach(path => {
let coordinatesArray = path.points.coordinates
coordinatesArray.forEach(coordinates => {
Expand All @@ -68,6 +94,7 @@ export default class SafetyStore extends Store<IndexStoreState> {
}

private static checkSegmentInStore(coordinatesInput: number[], indexStoreState: IndexStoreState): boolean {
// TODO (Jingwen): edit this method to use the updated data structure of IndexStoreState
if (indexStoreState.Segments != null) {
for (let segmentWithIndex of indexStoreState.Segments) {
let coordinates = segmentWithIndex.coordinates
Expand Down
4 changes: 3 additions & 1 deletion src/stores/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Path } from "@/api/graphhopper"


// index of safety or congestion
export interface IndexStoreState {
Expand All @@ -9,7 +11,7 @@ export interface SegmentWithIndex {
index: number
}

export interface PathWithIndex {
export interface PathWithIndex extends Path {
segments: SegmentWithIndex[],
overAllIndex: number
}

0 comments on commit 6ac205f

Please sign in to comment.