diff --git a/src/Informedica.GenSolver.Lib/Exceptions.fs b/src/Informedica.GenSolver.Lib/Exceptions.fs index 011e3f7..9a64cb2 100644 --- a/src/Informedica.GenSolver.Lib/Exceptions.fs +++ b/src/Informedica.GenSolver.Lib/Exceptions.fs @@ -3,11 +3,12 @@ namespace Informedica.GenSolver.Lib module Exceptions = - /// Equation exception + /// Solver exception exception SolverException of Exceptions.Message list - /// Raise an `EquationException` with `Message` `m`. + /// Raise an `EquationException` with `Message` `m` and adds it to + /// the list of `errs`. let raiseExc log errs m = match log with diff --git a/src/Informedica.GenSolver.Lib/Types.fs b/src/Informedica.GenSolver.Lib/Types.fs index 05dc873..588f53d 100644 --- a/src/Informedica.GenSolver.Lib/Types.fs +++ b/src/Informedica.GenSolver.Lib/Types.fs @@ -16,17 +16,21 @@ module rec Types = type Name = Name of string + /// /// The minimal value in /// a `ValueRange`. Can be inclusive /// or exclusive. + /// type Minimum = | MinIncl of ValueUnit | MinExcl of ValueUnit + /// /// The maximum value in /// a `ValueRange`. Can be inclusive /// or exclusive. + /// type Maximum = | MaxIncl of ValueUnit | MaxExcl of ValueUnit @@ -44,70 +48,85 @@ module rec Types = type Increment = Increment of ValueUnit - /// - /// Represents a domain of rational numbers. - /// - /// - /// A `ValueRange` can be one of the following: - /// - /// `Unrestricted`: any rational number - /// `Increment`: any number that is a multiple of an increment - /// `Min`: has a minimum - /// `MinIncrement`: a minimum with the domain consisting of multiples of one increment - /// `Max`: has a maximum - /// `IncrementMax`: a domain of multiples of an increment with a maximum - /// `MinMax`: has both a minimum and maximum - /// - /// - type ValueRange = - | Unrestricted - | NonZeroNoneNegative - | Min of Minimum - | Max of Maximum - | MinMax of Minimum * Maximum - | Incr of Increment - | MinIncr of min: Minimum * incr: Increment - | IncrMax of incr: Increment * max: Maximum - | MinIncrMax of min: Minimum * incr: Increment * max: Maximum - | ValSet of ValueSet // Set + /// + /// Represents a domain of rational numbers. + /// + /// + /// A `ValueRange` can be one of the following: + /// + /// `Unrestricted`: any rational number + /// `NonZeroNoneNegative`: any positive rational number greater than zero + /// `Min`: has a minimum + /// `Max`: has a maximum + /// `MinMax`: has both a minimum and maximum + /// `Incr`: any number that is a multiple of an increment + /// `MinIncr`: a minimum with the domain consisting of multiples of one increment + /// `IncrMax`: a domain of multiples of an increment with a maximum + /// `MinIncrMax`: a minimum with a domain of multiples of an increment with a maximum + /// `ValSet`: a set of discrete values + /// + /// + type ValueRange = + | Unrestricted + | NonZeroNoneNegative + | Min of Minimum + | Max of Maximum + | MinMax of Minimum * Maximum + | Incr of Increment + | MinIncr of min: Minimum * incr: Increment + | IncrMax of incr: Increment * max: Maximum + | MinIncrMax of min: Minimum * incr: Increment * max: Maximum + | ValSet of ValueSet // Set + /// /// Represents a variable in an /// `Equation`. The variable is /// identified by `Name` and has /// a `Values` described by the /// `ValueRange`. + /// type Variable = { Name: Name; Values: ValueRange } + /// /// Represents a property of a `Variable`. + /// type Property = | MinProp of Minimum | MaxProp of Maximum | IncrProp of Increment | ValsProp of ValueSet + + /// /// An equation is either a `ProductEquation` /// or a `Sumequation`, the first variable is the /// dependent variable, i.e. the result of the /// equation, the second part are the independent /// variables in the equation + /// type Equation = | ProductEquation of Variable * Variable list | SumEquation of Variable * Variable list + + /// /// The `Result` of solving an `Equation` /// is that either the `Equation` is the /// same or has `Changed`. + /// type SolveResult = | Unchanged | Changed of List | Errored of Exceptions.Message list + /// /// Represents a constraint on a `Variable`. /// I.e. either a set of values, or an increment /// or a minimum of maximum. + /// type Constraint = { Name: Name diff --git a/src/Informedica.GenSolver.Lib/Utils.fs b/src/Informedica.GenSolver.Lib/Utils.fs index 5ad4074..e94f988 100644 --- a/src/Informedica.GenSolver.Lib/Utils.fs +++ b/src/Informedica.GenSolver.Lib/Utils.fs @@ -42,8 +42,10 @@ module Utils = /// Whether the exact values should be printed /// /// - /// ValueUnit.create [| 1N; 2N |] Units.Mass.milliGram |> toStr false - /// + /// [| 1N/3N |] |> ValueUnit.create Units.Mass.milliGram |> toStr false + /// // returns "0,333 mg" + /// [| 1N/3N |] |> ValueUnit.create Units.Mass.milliGram |> toStr true + /// // returns "1/3 mg" /// /// let toStr exact = @@ -56,6 +58,19 @@ module Utils = toStringDecimalDutchShortWithPrec 3 + /// + /// Print a ValueUnit to a string with a given precision delimited by "#" for Value and "|" for Unit + /// + /// The precision with which value should be printed + /// The ValueUnit to print + /// + /// + /// [| 1N/3N |] |> ValueUnit.create Units.Mass.milliGram |> toDelimitedString 2 + /// // returns "#0,33# |mg|" + /// [| 1N/3N; 1N/5N |] |> ValueUnit.create Units.Mass.milliGram |> toDelimitedString 2 + /// // returns "#0,33#, #0,2# |mg|" + /// + /// let toDelimitedString prec vu = let u = vu @@ -122,7 +137,7 @@ module Utils = /// Match an operator `op` to either /// multiplication, division, addition - /// or subtraction, returns `NoOp` when + /// or subtraction, fails when /// the operation is neither. let (|Mult|Div|Add|Subtr|) op = match op with diff --git a/src/Informedica.GenSolver.Lib/Variable.fs b/src/Informedica.GenSolver.Lib/Variable.fs index e3441aa..5cbb70d 100644 --- a/src/Informedica.GenSolver.Lib/Variable.fs +++ b/src/Informedica.GenSolver.Lib/Variable.fs @@ -16,6 +16,7 @@ module Variable = open Informedica.Utils.Lib.BCL + /// Create with continuation with **succ** function /// when success and **fail** function when failure. /// Creates a `Name` from a`string`. @@ -34,6 +35,7 @@ module Variable = /// an `NameException` when it fails. let createExc = create id (raiseExc []) + /// Return the `string` value of a `Name`. let toString (Name s) = s