/// <summary> /// Initializes a new instance of the <see cref="RootFunction" /> class. /// </summary> /// <param name="index">The index.</param> /// <param name="radicand">The radicand.</param> /// <param name="sequence">The sequence.</param> /// <param name="exponent">The exponent.</param> /// <param name="editable">if set to <see langword="true" /> [editable].</param> public RootFunction(ICoefficient index, IExpression radicand, INumeric?sequence = null, IExpression?exponent = null, bool editable = false) { Parent = null; Index = index; if (Index is IExpression i) { i.Parent = this; } Radicand = radicand; if (Radicand is IExpression r) { r.Parent = this; } Sequence = sequence; if (Radicand is ICoefficient s) { s.Parent = this; } Exponent = exponent; if (Radicand is ICoefficient e) { e.Parent = this; } Editable = editable; }
public override ICoefficient[] Read(string path, out string title, out ICoefficient sizeFunctionMultiplier, out ICoefficient nestCoefficient) { title = null; sizeFunctionMultiplier = null; nestCoefficient = null; return(new Coefficient[100]); }
public ChoiceProbabilityCalculator(bool modelIsInEstimationMode, ICoefficient[] coefficients, ICoefficient sizeFunctionMultiplier, string title, int totalAlternatives, int totalNestedAlternatives, int totalLevels, int totalUtilities, int totalObservationItems) { if (coefficients == null) { throw new FileNotFoundException("The coefficient file was not found."); } _instanceId = _instance++; _modelIsInEstimationMode = modelIsInEstimationMode; _coefficients = coefficients; _sizeFunctionMultiplier = sizeFunctionMultiplier; _title = title; _alternatives = new Alternative[totalAlternatives]; _nestedAlternatives = new NestedAlternative[totalNestedAlternatives]; _levels = new Level[totalLevels]; if (Global.Configuration.TestEstimationModelInApplicationMode && _estimationCalculator == null) { var temp1 = new FileInfo(Global.GetEstimationPath(Global.Configuration.OutputAlogitDataPath) + ".tst"); _tempWriter = new StreamWriter(temp1.Open(FileMode.Create, FileAccess.Write, FileShare.Read)); _estimationCalculator = this; _nAlternatives = totalAlternatives; _nChosenAndAvail = new int[totalAlternatives]; _nPredicted = new int[totalAlternatives]; _nAvailable = new int[totalAlternatives]; _nChosenNotAvail = new int[totalAlternatives]; _nChosenOnlyAvail = new int[totalAlternatives]; _totalProb = new double[totalAlternatives]; } if (!modelIsInEstimationMode) { return; } _estimationCalculator = this; _totalUtilities = totalUtilities; _observation = new IObservationItem[totalObservationItems]; if (!Global.Configuration.ShouldOutputAlogitData) { return; } var temp2 = new FileInfo(Global.GetEstimationPath(Global.Configuration.OutputAlogitDataPath) + ".tmp"); if (temp2.Directory != null && !temp2.Directory.Exists) { temp2.Directory.Create(); } _tempWriter = new StreamWriter(temp2.Open(FileMode.Create, FileAccess.Write, FileShare.Read)); }
/// <summary> /// Initializes a new instance of the <see cref="ProductTerm" /> class. /// </summary> /// <param name="coefficient">The coefficient.</param> /// <param name="editable">if set to <see langword="true" /> [editable].</param> /// <param name="expressions">The expressions.</param> public ProductTerm(ICoefficient coefficient, bool editable = false, params IFactor[] expressions) { Parent = null; Coefficient = coefficient; if (Coefficient is IChild c) { c.Parent = this; } Factors = new List <IFactor>(expressions); for (var i = 0; i < Factors.Count; i++) { if (Factors[i] is IExpression f) { f.Parent = this; } } Editable = editable; }
public bool IsEquivalentType(ICoefficient coef) { return this.GetType() == coef.GetType() && this.CountGoals == ((CoefAndGoals) coef).CountGoals; }
public bool IsEquivalentType(ICoefficient coef) { return this.GetType() == coef.GetType(); }
public virtual ICoefficient[] Read(string path, out string title, out ICoefficient sizeFunctionMultiplier, out ICoefficient nestCoefficient) { title = null; sizeFunctionMultiplier = null; nestCoefficient = null; var coefficients = new Dictionary <int, Coefficient>(); var file = new FileInfo(path); var baseSizeVariableFound = false; using (var reader = new CountingReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))) { string line; while ((line = reader.ReadLine()) != null) { if (line.Trim() == "END") { break; } if (string.IsNullOrEmpty(title)) { title = line; } } while ((line = reader.ReadLine()) != null) { if (line.Trim() == "-1") { break; } var tokens = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length < 1) { continue; } int parameter; int.TryParse(tokens[0], out parameter); var label = tokens[1].Trim(); var constraint = tokens[2]; double coefficientValue; double.TryParse(tokens[3], out coefficientValue); var coefficient = new Coefficient { Parameter = parameter, Label = label, Constraint = constraint, Value = coefficientValue, IsSizeVariable = label.StartsWith("Gamm"), IsParFixed = constraint.ToLower() == "t" || constraint.ToLower() == "c", IsSizeFunctionMultiplier = label.StartsWith("LSM_"), IsNestCoefficient = label.StartsWith("Nest") }; if (coefficient.IsSizeFunctionMultiplier) { sizeFunctionMultiplier = coefficient; } if (coefficient.IsNestCoefficient) { nestCoefficient = coefficient; } if (!baseSizeVariableFound && coefficient.IsSizeVariable && coefficient.IsParFixed && coefficient.Value.AlmostEquals(0)) { baseSizeVariableFound = true; coefficient.IsBaseSizeVariable = true; } coefficients.Add(parameter, coefficient); } } var max = coefficients.Values.Max(c => c.Parameter) + 1; var array = new Coefficient[max]; for (var i = 0; i <= max; i++) { Coefficient coefficient; if (coefficients.TryGetValue(i, out coefficient)) { array[i] = coefficient; } } return(array); }
/// <summary> /// Initializes a new instance of the <see cref="ProductTerm" /> class. /// </summary> /// <param name="coefficient">The coefficient.</param> /// <param name="expressions">The expressions.</param> public ProductTerm(ICoefficient coefficient, params IFactor[] expressions) : this(coefficient, false, expressions) { }