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

Add a SolverConfig type #266

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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