From 1345d7940fe56dc3e00f1d6ef7715abc8f1b5875 Mon Sep 17 00:00:00 2001 From: Yves Dubromelle Date: Sat, 6 Feb 2016 14:53:18 +0100 Subject: [PATCH] fix #15 : choose a car --- Makefile | 1 + hahp-example/Main.hs | 2 + hahp.cabal | 1 + src/HAHP/Sample/CarChoice.hs | 125 +++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 src/HAHP/Sample/CarChoice.hs diff --git a/Makefile b/Makefile index 35495c1..d42de6e 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ build: pdf: build $(EXECUTABLE) > out.md pandoc out.md -o out.pdf -V geometry:a4paper -V geometry:margin=2cm + date #---- Improvement diff --git a/hahp-example/Main.hs b/hahp-example/Main.hs index 00d2ade..e993f65 100644 --- a/hahp-example/Main.hs +++ b/hahp-example/Main.hs @@ -7,6 +7,7 @@ import HAHP.Reporting import HAHP.Sample.Config1 import HAHP.Sample.Config2 import HAHP.Sample.Config3 +import HAHP.Sample.CarChoice import HAHP.Sample.LeaderChoice import HAHP.Sample.SquareMatrixError @@ -19,6 +20,7 @@ main = do --, (sampleAHPConfig3, sampleAlternatives3) --, (smeConfig, smeAlternatives) (leaderChoiceTree, leaderChoiceAlternatives) + , (carChoiceTree, carChoiceAlternatives) ] time <- getCurrentTime diff --git a/hahp.cabal b/hahp.cabal index 9486c23..c6e634c 100644 --- a/hahp.cabal +++ b/hahp.cabal @@ -31,6 +31,7 @@ library HAHP.Sample.Config1 HAHP.Sample.Config2 HAHP.Sample.Config3 + HAHP.Sample.CarChoice HAHP.Sample.LeaderChoice HAHP.Sample.SquareMatrixError HAHP.Validation.Alternatives diff --git a/src/HAHP/Sample/CarChoice.hs b/src/HAHP/Sample/CarChoice.hs new file mode 100644 index 0000000..fa6b7b1 --- /dev/null +++ b/src/HAHP/Sample/CarChoice.hs @@ -0,0 +1,125 @@ +module HAHP.Sample.CarChoice where + +import Data.Map +import HAHP.Data +import Numeric.LinearAlgebra.HMatrix + +carChoiceTree :: AHPTree +carChoiceTree = + AHPTree "Choose the best car for the Jones family" + ( (4><4) + [ 1, 3, 7, 3 + , 1/3, 1, 9, 1 + , 1/7, 1/9, 1, 1/7 + , 1/3, 1, 7, 1 + ] + ) + Nothing + Nothing + Nothing + [ AHPTree "Cost" + ( (4><4) + [ 1, 2, 5, 3 + , 1/2, 1, 2, 2 + , 1/5, 1/2, 1, 1/2 + , 1/3, 1/2, 2, 1 + ] + ) + Nothing + Nothing + Nothing + [ AHPLeaf "Purchase Price" True Nothing + , AHPLeaf "Fuel Costs" True Nothing + , AHPLeaf "Maintenance Costs" True Nothing + , AHPLeaf "Resale Value" True Nothing + ] + , AHPLeaf "Safety" True Nothing + , AHPLeaf "Style" True Nothing + , AHPTree "Capacity" + ( (2><2) + [ 1, 1/5 + , 5, 1 + ] + ) + Nothing + Nothing + Nothing + [ AHPLeaf "Cargo Capacity" True Nothing + , AHPLeaf "Passenger Capacity" True Nothing + ] + ] + +asValues = + insert "Purchase Price" 0.242 + . insert "Fuel Costs" 0.188 + . insert "Maintenance Costs" 0.357 + . insert "Resale Value" 0.225 + . insert "Safety" 0.215 + . insert "Style" 0.346 + . insert "Cargo Capacity" 0.090 + . insert "Passenger Capacity" 0.136 + $ empty + +ahValues = + insert "Purchase Price" 0.027 + . insert "Fuel Costs" 0.212 + . insert "Maintenance Costs" 0.312 + . insert "Resale Value" 0.095 + . insert "Safety" 0.215 + . insert "Style" 0.346 + . insert "Cargo Capacity" 0.090 + . insert "Passenger Capacity" 0.136 + $ empty + +psuvValues = + insert "Purchase Price" 0.027 + . insert "Fuel Costs" 0.133 + . insert "Maintenance Costs" 0.084 + . insert "Resale Value" 0.055 + . insert "Safety" 0.083 + . insert "Style" 0.045 + . insert "Cargo Capacity" 0.170 + . insert "Passenger Capacity" 0.273 + $ empty + +crvValues = + insert "Purchase Price" 0.242 + . insert "Fuel Costs" 0.160 + . insert "Maintenance Costs" 0.100 + . insert "Resale Value" 0.415 + . insert "Safety" 0.038 + . insert "Style" 0.160 + . insert "Cargo Capacity" 0.170 + . insert "Passenger Capacity" 0.136 + $ empty + +esuvValues = + insert "Purchase Price" 0.362 + . insert "Fuel Costs" 0.151 + . insert "Maintenance Costs" 0.089 + . insert "Resale Value" 0.105 + . insert "Safety" 0.025 + . insert "Style" 0.025 + . insert "Cargo Capacity" 0.170 + . insert "Passenger Capacity" 0.046 + $ empty + +omValues = + insert "Purchase Price" 0.100 + . insert "Fuel Costs" 0.156 + . insert "Maintenance Costs" 0.058 + . insert "Resale Value" 0.105 + . insert "Safety" 0.424 + . insert "Style" 0.078 + . insert "Cargo Capacity" 0.310 + . insert "Passenger Capacity" 0.273 + $ empty + +carChoiceAlternatives :: [Alternative] +carChoiceAlternatives = [ Alternative "Accord Sedan" asValues + , Alternative "Accord Hybrid" ahValues + , Alternative "Pilot SUV" psuvValues + , Alternative "CR-V SUV" crvValues + , Alternative "Element SUV" esuvValues + , Alternative "Odyssey Minivan" omValues + ]