Skip to content

Commit

Permalink
Change IndexStoreState to SafetyStoreState
Browse files Browse the repository at this point in the history
Because we do not need congestion now
  • Loading branch information
alicia-lyu committed Aug 17, 2023
1 parent 5872874 commit bf15347
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
35 changes: 25 additions & 10 deletions src/stores/SafetyStore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { RouteStoreCleared, RouteStoreLoaded } from "@/actions/Actions";
import { IndexStoreState, SegmentWithIndex } from ".";
import RouteStore from "./RouteStore";
import Store from "./Store";
import { Path } from "@/api/graphhopper";
import { calcGaussianRandom } from './utils'
import { Path } from "@/api/graphhopper";

// index of safety or congestion
export interface SafetyStoreState {
paths: PathWithSafety[]
}

export interface SegmentWithSafety {
coordinates: number[][],
index: number
}

export interface PathWithSafety extends Path {
segments: SegmentWithSafety[],
overAllIndex: number
}

export default class SafetyStore extends Store<IndexStoreState> {
export default class SafetyStore extends Store<SafetyStoreState> {
readonly routeStore: RouteStore

private static safestPathFound: boolean = false
Expand All @@ -16,13 +30,13 @@ export default class SafetyStore extends Store<IndexStoreState> {
this.routeStore = routeStore
}

private static getInitialState(): IndexStoreState {
private static getInitialState(): SafetyStoreState {
return {
paths: []
}
}

reduce(state: IndexStoreState, action: any): IndexStoreState {
reduce(state: SafetyStoreState, action: any): SafetyStoreState {
if (action instanceof RouteStoreCleared) {
return SafetyStore.getInitialState()
} else if (action instanceof RouteStoreLoaded) {
Expand All @@ -44,7 +58,7 @@ export default class SafetyStore extends Store<IndexStoreState> {
* in addition to the paths already in route store
* @returns the new state of SafetyStore
*/
private static generateSafetyForPaths(state: IndexStoreState, action: RouteStoreLoaded): IndexStoreState {
private static generateSafetyForPaths(state: SafetyStoreState, action: RouteStoreLoaded): SafetyStoreState {
const newPaths = action.newPaths;
const middlePointAdded = action.middlePointsAdded;
// Use ⬆ and safestPathFound and secondSafestPathFound to find the #1, #2 safest paths:
Expand All @@ -62,22 +76,23 @@ export default class SafetyStore extends Store<IndexStoreState> {
if (!this.checkSegmentInStore(coordinates, this.indexStoreState)) {
// replace this.indexStoreState with state
let safetyIndex = calcGaussianRandom(0.1, 0.01)
let newSegment: SegmentWithIndex = {
let newSegment: SegmentWithSafety = {
coordinates: [coordinates],
index: safetyIndex
}
this.indexStoreState.Segments.push(newSegment)
}
})
})
return this.indexStoreState
return this.indexStoreState
}

private static checkSegmentInStore(coordinatesInput: number[], indexStoreState: IndexStoreState): boolean {
// change indexStoreState to safetyStoreState
// 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
for (let SegmentWithSafety of indexStoreState.Segments) {
let coordinates = SegmentWithSafety.coordinates
if (coordinates[0][0] == coordinatesInput[0] && coordinates[0][1] == coordinatesInput[1]) {
return true
}
Expand Down
17 changes: 0 additions & 17 deletions src/stores/index.d.ts

This file was deleted.

0 comments on commit bf15347

Please sign in to comment.