Skip to content

Commit

Permalink
perf: very small improvement only sort when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Oct 24, 2023
1 parent 24c314f commit 2af12d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
34 changes: 20 additions & 14 deletions src/Informedica.GenSolver.Lib/Equation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ module Equation =
// calcVars returns None
let rec loop acc vars =
let vars =
vars
|> List.sortBy(fun (_, xs) ->
xs
|> List.tail
|> List.sumBy Variable.count
)
if onlyMinIncrMax then vars
else
vars
|> List.sortBy(fun (_, xs) ->
xs
|> List.tail
|> List.sumBy Variable.count
)

match calcVars vars with
| None -> acc, vars
Expand All @@ -425,22 +427,26 @@ module Equation =
i,
xs |> List.replace (Variable.eqName var) var
)
|> List.sortBy(fun (_, xs) ->
xs
|> List.tail
|> List.sumBy Variable.count
)
|> fun vars ->
if onlyMinIncrMax then vars
else
vars
|> List.sortBy(fun (_, xs) ->
xs
|> List.tail
|> List.sumBy Variable.count
)
|> loop (acc |> List.replaceOrAdd (Variable.eqName var) var)

vars
|> loop []
|> fun (c, vars) ->
if c |> List.isEmpty then eq, Unchanged
|> fun (changed, vars) ->
if changed |> List.isEmpty then eq, Unchanged
else
// calculate which vars are changed from the original eq
let solveResult =
let vars = eq |> toVars
c
changed
|> List.map (fun v2 ->
vars
|> List.tryFind (Variable.eqName v2)
Expand Down
4 changes: 2 additions & 2 deletions src/Informedica.GenSolver.Lib/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ module Utils =

/// Maximum set of values that can be used to perform
/// a Variable calculation.
let MAX_CALC_COUNT = 200
let MAX_CALC_COUNT = 300

/// Reduce a set of values to a maximum of 20 for a Variable
let PRUNE = 20
let PRUNE = 40

/// Maximum quantity of a numerator or denominator to prevent
/// infinite loops calculating a minimum or maximum.
Expand Down

0 comments on commit 2af12d4

Please sign in to comment.