An error occurred while loading the file. Please try again.
-
Guillaume Perréal authorede623e915
import { Debug } from './base';
/**
* domaine de définition du paramètre
*/
export enum ParamDomainValue {
/**
* >0, =0, <0
*/
ANY,
/**
* >=0
*/
POS_NULL,
/**
* > 0
*/
POS,
/**
* <>0
*/
NOT_NULL,
/**
* interval
*/
INTERVAL
}
export class ParamDomain {
private _value: ParamDomainValue;
private _min: number;
private _max: number;
constructor(d: ParamDomainValue, min: number = 0, max: number = -1) {
this.checkValue(d, min, max);
this._value = d;
this._min = min;
this._max = max;
}
private checkValue(val, min, max) {
switch (val) {
case ParamDomainValue.INTERVAL:
if (min > max)
throw "invalid " + min + "/" + max + " min/max boundaries for 'interval' parameter definition domain"
break;
default:
break;
}
}
get value() {
return this._value;
}
get min() {
return this._min;
}
get max() {
return this._max;
}
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
}
/**
* calculabilité du paramètre
*/
export enum ParamCalculability {
/**
* paramètre fixé
*/
NONE,
/**
* paramètre calculable analytiquement, par méthode de Newton, ...
*/
EQUATION,
/**
* paramètre calculable par dichotomie
*/
DICHO
}
/**
* définition d'un paramètre
*/
export class ParamDefinition {
/**
* symbole
*/
private _symbol: string;
/**
* calculabilité
*/
private _calc: ParamCalculability;
/**
* domaine de définition
*/
private _domain: ParamDomain;
/**
* ancienne valeur du paramètre
*/
// private _savedValue: number;
/**
* valeur du paramètre
*/
private _value: number;
// constructor(s: string, d: ParamDomain, c: ParamCalculability, val: number = undefined) {
constructor(s: string, d: any, val: number = undefined) {
this._symbol = s;
if (d instanceof ParamDomain)
this._domain = d;
else
this._domain = new ParamDomain(<ParamDomainValue>d);
this._calc = undefined;
this.checkValue(val);
this._value = val;
}
get() {
return this._value;
}
/**
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
* getter symbole
*/
get symbol(): string {
return this._symbol;
}
/*
* méthodes de calculabilité
*/
/**
* variable calculable ?
*/
isComputable(): boolean {
return this.calculability != ParamCalculability.NONE;
}
/**
* variable calculable par l'équation ?
*/
isAnalytical(): boolean {
return this.calculability == ParamCalculability.EQUATION;
}
get calculability(): ParamCalculability {
if (this._calc == undefined)
throw "value of parameter '" + this._symbol + "' calculability is not defined";
return this._calc;
}
set calculability(c: ParamCalculability) {
this._calc = c;
}
/**
* gestion de la valeur
*/
get v(): number {
if (this._value == undefined)
throw "value of '" + this._symbol + "' parameter is not defined";
return this._value;
}
set v(val: number) {
if (this.calculability == ParamCalculability.NONE)
throw "value of '" + this._symbol + "' parameter cannot be changed";
this.checkValue(val);
this._value = val;
}
get uncheckedValue() {
return this._value;
}
private checkValue(v: number) {
let sDomain = ParamDomainValue[this._domain.value];
switch (this._domain.value) {
case ParamDomainValue.ANY:
break;
case ParamDomainValue.POS:
if (v <= 0)
throw "parameter '" + this._symbol + "' : invalid " + v + " value (cannot be <=0)";
break;
case ParamDomainValue.POS_NULL:
if (v < 0)
throw "parameter '" + this._symbol + "' : invalid " + v + " value (cannot be <0)";
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
break;
case ParamDomainValue.NOT_NULL:
if (v == 0)
throw "parameter '" + this._symbol + "' : value cannot be 0";
break;
case ParamDomainValue.INTERVAL:
let min = this._domain.min;
let max = this._domain.max;
if (v < min || v > max)
throw "parameter '" + this._symbol + "' : value " + v + " is out of [" + min + ", " + max + "] interval";
break;
default:
throw "parameter '" + this._symbol + "' : non supported '" + sDomain + "' definition domain";
}
}
isDefined(): boolean {
return this._value != undefined;
}
undefine() {
this._value = undefined;
// this._savedValue = undefined;
}
/**
* gestion du cache
*/
/*
saveValue() {
if (this._value == undefined)
throw "parameter '" + this._symbol + "' : cannot save 'undefined' value";
if (this._savedValue != undefined)
throw "parameter '" + this._symbol + "' : previous saved value " + this._savedValue + " has not been restored";
this._savedValue = this._value;
}
restoreValue() {
if (this._savedValue == undefined)
throw "parameter '" + this._symbol + "' : value has not been saved";
this._value = this._savedValue;
this._savedValue = undefined;
}
*/
toString(): string {
if (this.isDefined())
return "" + this._value;
return "undefined";
}
}
/**
* liste des paramètres d'une équation
*/
export interface IParamsEquation {
//[key: string]: ParamDefinition; // map : array of ParamDefinition with string keys
// [key: string]: number; // map : array of ParamDefinition with string keys
}
/**
* noeud de calcul
*/
export abstract class ComputeNode extends Debug {
protected _prms: IParamsEquation;
281282283284285286287288289290
protected abstract setParametersCalculability();
constructor(prms: IParamsEquation, dbg: boolean = false) {
super(dbg);
this._prms = prms;
this.setParametersCalculability();
}
}