Skip to content

Commit

Permalink
feat: looping over min incr max to valueset
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Oct 28, 2023
1 parent c9ef84b commit 64e90a7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ COPY --from=server-build /workspace/deploy /app
COPY --from=client-build /workspace/deploy /app/public
COPY src/Server/data /app/data

# setting this env variable disables file logging
ENV GENPRES_PROD=""
WORKDIR /app
EXPOSE 8085
Expand Down
9 changes: 8 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* ~~Add cont med preparation popus~~
* Add ventilation tab
* ~~Responsive design for tablets and smartphones~~
* Add navigation to allow opening with age and weight in url
* ~~Add navigation to allow opening with age and weight in url~~
* Sliders for mobile input
* Add protocols tab
* Allow for preparation calculation with multiple concentrations
Expand All @@ -39,3 +39,10 @@
* Make tables sortable
* ~~Automate setting of build version~~
* Refactor navbar, use burger and menu

## Ideas
* ~~Disable MinIncrMax to ValueSet~~
* Apply constraints, first Increment then ValueSet instead
* Remove exception throwing from Solver when too many values or expensive calculation


53 changes: 32 additions & 21 deletions src/Informedica.GenOrder.Lib/Order.fs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ module Order =
(c.OrderableQuantity |> Quantity.toOrdVar |> OrderVariable.getVar).Values
)
]
|> List.choose (Variable.ValueRange.getIncr)
|> List.choose Variable.ValueRange.getIncr
|> List.minBy (fun i ->
i
|> Variable.ValueRange.Increment.toValueUnit
Expand Down Expand Up @@ -1438,27 +1438,38 @@ module Order =
let solveOrder printErr logger = solve false printErr logger


let minIncrMaxToValues (ord: Order) =
let mutable flag = false
let ovars =
ord
|> toOrdVars
|> List.map (fun ovar ->
if flag || ovar.Constraints.Incr |> Option.isNone then ovar
else
flag <- true
let n =
match ord.Prescription with
| Continuous -> 100
| Discontinuous _ -> 50
| Timed _ -> 5

ovar
|> OrderVariable.minIncrMaxToValues n
)
let minIncrMaxToValues logger (ord: Order) =
let rec loop runAgain ord =
if not runAgain then ord
else
let mutable flag = false
let ovars =
ord
|> toOrdVars
|> List.map (fun ovar ->
if flag ||
ovar.Constraints.Incr |> Option.isNone ||
ovar.Variable.Values |> ValueRange.isMinIncrMax |> not then ovar
else
flag <- true
let n =
match ord.Prescription with
| Continuous -> 100
| Discontinuous _ -> 50
| Timed _ -> 5

ovar
|> OrderVariable.minIncrMaxToValues n
)

ord
|> fromOrdVars ovars
|> solveOrder false logger
|> function
| Ok ord -> loop flag ord
| Error _ -> ord

ord
|> fromOrdVars ovars
loop true ord
// |> fun ord ->
// let s = ord |> toString |> String.concat "\n"
// printfn $"min incr max to values:\n{s}"
Expand Down
4 changes: 2 additions & 2 deletions src/Informedica.GenSolver.Lib/Solver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ module Solver =
/// a list of replaced `Equation` and a list
/// of unchanged `Equation`
/// </summary>
/// <param name="vs">The list of `Variable` to replace</param>
/// <param name="es">The list of `Equation` to replace in</param>
/// <param name="vars">The list of `Variable` to replace</param>
/// <param name="eqs">The list of `Equation` to replace in</param>
let replace vars eqs =
let rpl, rst =
eqs
Expand Down
3 changes: 2 additions & 1 deletion src/Informedica.GenSolver.Lib/Variable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3196,7 +3196,8 @@ module Variable =
/// Calculate a ValueSet for a Variable if the Value of the
/// Variable is a MinIncrMax
/// </summary>
/// <param name="var"></param>
/// <param name="var">The variable to change min incr max to a ValueSet</param>
/// <param name="n">Prune the ValueSet to n</param>
/// <returns>A Variable with a ValueSet if this can be calculated</returns>
let minIncrMaxToValues n var =
if var |> isMinIncrMax |> not then var
Expand Down
6 changes: 5 additions & 1 deletion src/Server/ScenarioResult.fs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,15 @@ Scenarios: {sc.Scenarios |> Array.length}


let calcMinIncrMaxToValues (ord : Order) =
if Env.getItem "GENPRES_PROD" |> Option.isNone then
let path = $"{__SOURCE_DIRECTORY__}/log.txt"
OrderLogger.logger.Start (Some path) OrderLogger.Level.Informative

try
ord
|> mapFromOrder
|> Order.Dto.fromDto
|> Order.minIncrMaxToValues
|> Order.minIncrMaxToValues OrderLogger.logger.Logger
|> Order.Dto.toDto
|> mapToOrder
|> Ok
Expand Down

0 comments on commit 64e90a7

Please sign in to comment.