Skip to content

Commit

Permalink
Add a SolverConfig type
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Sep 27, 2024
1 parent 1e4ef94 commit 623667a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
55 changes: 36 additions & 19 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,45 @@ interface Scoring {
}

interface Opt {
scoring: Scoring;
flight: IGCFile & {
/** Filtered GPS fixes when invalid=false, GPS fix number is relative to this array */
filtered: BRecord[];
};
/** launch and landing are the indices of the fixes identified as launch and landing **/
launch: number;
landing: number;
config: { [key: string]: any };
scoring: Scoring;
flight: IGCFile & {
/** Filtered GPS fixes when invalid=false, GPS fix number is relative to this array */
filtered: BRecord[];
};
/** launch and landing are the indices of the fixes identified as launch and landing **/
launch: number;
landing: number;
config: SolverConfig;
}

interface Solution {
bound: number;
currentUpperBound: number;
id: number | string;
opt: Opt;
optimal?: boolean;
processed?: number;
score?: number;
scoreInfo?: ScoreInfo;
time?: number;
bound: number;
currentUpperBound: number;
id: number | string;
opt: Opt;
optimal?: boolean;
processed?: number;
score?: number;
scoreInfo?: ScoreInfo;
time?: number;
}

export function solver(flight: IGCFile, scoringRules: object, config?: { [key: string]: any }) : Iterator<Solution, Solution>;
interface SolverConfig {
/** maximum execution time of the solver in ms, each successive call will return a better solution, default undefined for unlimited */
maxcycle?: number;
/** do not include the flight track data in the output GeoJSON, default false */
noflight?: boolean;
/** include invalid GPS fixes when evaluating the flight, default false */
invalid?: boolean;
/** use high-precision distance calculation (Vincenty's), much slower for slightly higher precision, default false */
hp?: boolean;
/** automatically detect launch and landing and trim the flight track, default false */
trim?: boolean;
}

export function solver(
flight: IGCFile,
scoringRules: object,
config?: SolverConfig
): Iterator<Solution, Solution>;
export const scoringRules: { [key: string]: object[] };
8 changes: 4 additions & 4 deletions src/solver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* igc-xc-score Solver
* scoring library for paragliding flights
*
*
* @module igc-xc-score
* @author Momtchil Momtchev <[email protected]>
*/
Expand All @@ -17,8 +17,8 @@ import scoringRules from '../scoring-rules.config.js';
* This the solver
* @param {IGCFile} flight flight track data in the igc_parser format
* @param {object[]} [scoringTypes=undefined] undefined for FFVL or one of the elements of scoringRules
* @param {object=} config optional config parameters
* @param {number=} config.maxcycle maximum execution time of the solver in ms, each sucessive call will return a better solution, default undefined for unlimited
* @param {SolverConfig=} config optional config parameters
* @param {number=} config.maxcycle maximum execution time of the solver in ms, each successive call will return a better solution, default undefined for unlimited
* @param {boolean=} config.noflight do not include the flight track data in the output GeoJSON, default false
* @param {boolean=} config.invalid include invalid GPS fixes when evaluating the flight, default false
* @param {boolean=} config.hp use high-precision distance calculation (Vincenty's), much slower for slightly higher precision, default false
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function* solver(flight, _scoringTypes, _config) {
}

best.processed = processed;
const currentUpperBound = solutionQueue.findGreatest();
const currentUpperBound = solutionQueue.findGreatest();
best.currentUpperBound = currentUpperBound ? currentUpperBound.value.bound : best.bound;
tcum += Date.now() - tstart;
best.time = tcum;
Expand Down

0 comments on commit 623667a

Please sign in to comment.