Skip to content

Commit

Permalink
Fix warning due to deprecation of Solution.ObjectiveResult.
Browse files Browse the repository at this point in the history
* Rename the field of Solution and made them internal.
* Expose them via properties with the deprecation on the ObjectiveResult.
* When ObjectiveResult is removed, the corresponding internal ObjectiveValue can be removed in the entire codebase as well as the public properties. Moreover, DecisionResultsMap can be renamed back to DecisionResults.
  • Loading branch information
Florian Lorenzen committed May 16, 2024
1 parent 4252db4 commit 3992840
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
20 changes: 10 additions & 10 deletions Flips.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ module Types =
let decisions = DecisionBuilder "Test" { for n in names -> Boolean } |> SMap
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> decisions.[n], s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand Down Expand Up @@ -885,8 +885,8 @@ module Types =
let decisions = DecisionBuilder "Test" { for n in names -> Boolean } |> SMap2
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> decisions.[n], s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand Down Expand Up @@ -1149,8 +1149,8 @@ module Types =
let decisions = DecisionBuilder "Test" { for n in names -> Boolean } |> SMap3
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> decisions.[n], s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand Down Expand Up @@ -1569,8 +1569,8 @@ module Types =
let decisions = DecisionBuilder "Test" { for n in names -> Boolean } |> SMap4
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> decisions.[n], s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand Down Expand Up @@ -2259,8 +2259,8 @@ module Types =
let decisions = DecisionBuilder "Test" { for n in names -> Boolean } |> SMap5
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> decisions.[n], s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand Down
20 changes: 10 additions & 10 deletions Flips.Tests/UnitsOfMeasure.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ module UnitsOfMeasureTests =
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> let (Decision.Value d) = decisions.[n]
d, float s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand All @@ -372,8 +372,8 @@ module UnitsOfMeasureTests =
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> let (Decision.Value d) = decisions.[n]
d, float s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand All @@ -391,8 +391,8 @@ module UnitsOfMeasureTests =
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> let (Decision.Value d) = decisions.[n]
d, float s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand All @@ -410,8 +410,8 @@ module UnitsOfMeasureTests =
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> let (Decision.Value d) = decisions.[n]
d, float s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand All @@ -429,8 +429,8 @@ module UnitsOfMeasureTests =
let decisionResults = uniqueValues |> List.map (fun (n, (Scalar.Value s)) -> let (Decision.Value d) = decisions.[n]
d, float s) |> Map.ofList
let solution = {
ObjectiveResult = 0.0
DecisionResults = decisionResults
ObjectiveValue = 0.0
DecisionResultsMap = decisionResults
}

let resultValues =
Expand Down
8 changes: 4 additions & 4 deletions Flips/Solve.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ module internal ORTools =
|> Map.ofSeq

{
DecisionResults = decisionMap
ObjectiveResult = Flips.Types.LinearExpression.Evaluate (fun d -> decisionMap.[d]) objective.Expression
DecisionResultsMap = decisionMap
ObjectiveValue = Flips.Types.LinearExpression.Evaluate (fun d -> decisionMap.[d]) objective.Expression
}


Expand Down Expand Up @@ -313,8 +313,8 @@ module internal Optano =
|> Map.ofSeq

{
DecisionResults = decisionMap
ObjectiveResult = Flips.Types.LinearExpression.Evaluate (fun d -> decisionMap.[d]) objective.Expression
DecisionResultsMap = decisionMap
ObjectiveValue = Flips.Types.LinearExpression.Evaluate (fun d -> decisionMap.[d]) objective.Expression
}


Expand Down
11 changes: 7 additions & 4 deletions Flips/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,14 @@ type Objective = {
}

/// The results of the optimization if it was successful
type Solution = {
DecisionResults : Map<Decision,float>
[<Obsolete("Please use the Objective.evaluate function instead")>]
ObjectiveResult : float
type Solution = internal {
DecisionResultsMap : Map<Decision,float>
ObjectiveValue : float
}
with
[<Obsolete("Please use the Objective.evaluate function instead")>]
member this.ObjectiveResult: float = this.ObjectiveValue
member this.DecisionResults: Map<Decision,float> = this.DecisionResultsMap

/// The type of underlying solver to use
type SolverType =
Expand Down

0 comments on commit 3992840

Please sign in to comment.