Commit d857d8e8 authored by Thorsten Wißmann's avatar Thorsten Wißmann 🐧
Browse files

Add custom queries to smv output

parent 97d330db
...@@ -83,10 +83,16 @@ update msg model = ...@@ -83,10 +83,16 @@ update msg model =
Debug.log "error" "No rail example present" Debug.log "error" "No rail example present"
|> always Nothing |> always Nothing
Just example -> Just example ->
let
additional_queries =
case (parseQuery model.next_query) of
[] -> []
x -> [x]
in
Just Just
{ filename = example.name ++ ".smv" { filename = example.name ++ ".smv"
, content = , content =
NuSmvOutput.compile example NuSmvOutput.compile example additional_queries
|> NuSmvOutput.show |> NuSmvOutput.show
} }
in in
...@@ -139,13 +145,7 @@ update msg model = ...@@ -139,13 +145,7 @@ update msg model =
QueryRun -> QueryRun ->
let let
query = query =
model.next_query parseQuery model.next_query
-- extract all numbers, no matter how they are separated
|> Regex.find Regex.All (regex "[0-9]+")
|> List.map (.match)
|> List.filterMap (Result.toMaybe << String.toInt)
|> List.map (\x -> x - 1) -- make them 0-indexed.
|> ListUtils.dropDuplicates
in in
(model, RPCmd.SetQuery query) (model, RPCmd.SetQuery query)
...@@ -237,6 +237,15 @@ compileTraceLine line = ...@@ -237,6 +237,15 @@ compileTraceLine line =
|> RPCmd.Batch |> RPCmd.Batch
)) ))
parseQuery : String -> List Int
parseQuery =
-- extract all numbers, no matter how they are separated
Regex.find Regex.All (regex "[0-9]+")
>> List.map (.match)
>> List.filterMap (Result.toMaybe << String.toInt)
>> List.map (\x -> x - 1) -- make them 0-indexed.
>> ListUtils.dropDuplicates
viewQuery : List Int -> Html.Html a viewQuery : List Int -> Html.Html a
viewQuery query = viewQuery query =
let let
......
...@@ -268,10 +268,10 @@ showDetailedShuntMovement dsm = ...@@ -268,10 +268,10 @@ showDetailedShuntMovement dsm =
{-| {-|
Given a rail tree and the car positions, compute a smv file. Given a rail tree and the car positions, compute a smv file.
The query is still missing. Optionally, add some additional queries
-} -}
compile : RailExample -> SmvFile compile : RailExample -> List RailExample.Query -> SmvFile
compile rail_example = compile rail_example additional_queries =
let let
shunts : Array (NonEmptyList RT.Path) shunts : Array (NonEmptyList RT.Path)
shunts = -- the array of non-empty shunts shunts = -- the array of non-empty shunts
...@@ -463,6 +463,7 @@ compile rail_example = ...@@ -463,6 +463,7 @@ compile rail_example =
-- in order to get a 'Nothing' value for an empty query list -- in order to get a 'Nothing' value for an empty query list
-- replace that 'Nothing' by the default query of sorting the cars -- replace that 'Nothing' by the default query of sorting the cars
|> Maybe.withDefault ([List.indexedMap always rail_example.car_positions]) |> Maybe.withDefault ([List.indexedMap always rail_example.car_positions])
|> (flip (++) additional_queries)
|> List.map permutation2query |> List.map permutation2query
} }
......
...@@ -12,10 +12,13 @@ type alias RailExample = ...@@ -12,10 +12,13 @@ type alias RailExample =
{ name : String { name : String
, rail_net : RailTree (Has RT.Hint ()) (Has RT.Angles ()) , rail_net : RailTree (Has RT.Hint ()) (Has RT.Angles ())
, car_positions : List RT.Path , car_positions : List RT.Path
, queries : List (List Int) -- 0-indexed query , queries : List Query -- 0-indexed query
, rotation : Float -- the initial angle , rotation : Float -- the initial angle
} }
type alias Query = List Int
{-| permute the cars on a rail example {-| permute the cars on a rail example
That is the perm : List Int describes the order in which That is the perm : List Int describes the order in which
the cars appear in the initial configuration. the cars appear in the initial configuration.
...@@ -27,7 +30,7 @@ permute_by perm re = ...@@ -27,7 +30,7 @@ permute_by perm re =
} }
-- add a 1-indexed query -- add a 1-indexed query
addQuery : List Int -> RailExample -> RailExample addQuery : Query -> RailExample -> RailExample
addQuery perm re = addQuery perm re =
{ re { re
| queries = re.queries ++ [List.map (\x -> x - 1) perm] | queries = re.queries ++ [List.map (\x -> x - 1) perm]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment