Skip to content

Commit

Permalink
Remove Id from GameMap
Browse files Browse the repository at this point in the history
  • Loading branch information
gsvgit committed Jan 23, 2024
1 parent b5c95de commit 387e5e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
24 changes: 11 additions & 13 deletions VSharp.ML.GameServer.Runner/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ let mutable inTrainMode = true

let loadGameMaps (datasetDescriptionFilePath:string) =
let jsonString = File.ReadAllText datasetDescriptionFilePath
let maps = Dictionary<uint,GameMap>()
for map in System.Text.Json.JsonSerializer.Deserialize<GameMap[]> jsonString do
if not <| maps.ContainsKey map.Id
then maps.Add (map.Id, map)
else failwithf $"Id-s of maps must be unique, but maps contains more then one map with id{map.Id}."
let maps = ResizeArray<GameMap>()
for map in System.Text.Json.JsonSerializer.Deserialize<GameMap[]> jsonString do
maps.Add map
maps

let ws outputDirectory (webSocket : WebSocket) (context: HttpContext) =
Expand Down Expand Up @@ -193,25 +191,25 @@ let app port : WebPart =
path "/gameServer" >=> handShake (ws port)
]

let generateDataForPretraining outputDirectory datasetBasePath (maps:Dictionary<uint32,GameMap>) stepsToSerialize =
for kvp in maps do
if kvp.Value.StepsToStart = 0u<step>
let generateDataForPretraining outputDirectory datasetBasePath (maps:ResizeArray<GameMap>) stepsToSerialize =
for map in maps do
if map.StepsToStart = 0u<step>
then
printfn $"Generation for {kvp.Value.MapName} started."
let assembly = RunnerProgram.TryLoadAssembly <| FileInfo(Path.Combine (datasetBasePath, kvp.Value.AssemblyFullName))
let method = RunnerProgram.ResolveMethod(assembly, kvp.Value.NameOfObjectToCover)
printfn $"Generation for {map.MapName} started."
let assembly = RunnerProgram.TryLoadAssembly <| FileInfo(Path.Combine (datasetBasePath, map.AssemblyFullName))
let method = RunnerProgram.ResolveMethod(assembly, map.NameOfObjectToCover)
let aiTrainingOptions =
{
stepsToSwitchToAI = 0u<step>
stepsToPlay = 0u<step>
defaultSearchStrategy = searchMode.BFSMode
serializeSteps = true
mapName = kvp.Value.MapName
mapName = map.MapName
oracle = None
}
let options = VSharpOptions(timeout = 5 * 60, outputDirectory = outputDirectory, searchStrategy = SearchStrategy.ExecutionTreeContributedCoverage, stepsLimit = stepsToSerialize, solverTimeout=2, aiAgentTrainingOptions = aiTrainingOptions)
let statistics = TestGenerator.Cover(method, options)
printfn $"Generation for {kvp.Value.MapName} finished."
printfn $"Generation for {map.MapName} finished."
Application.reset()
API.Reset()
HashMap.hashMap.Clear()
Expand Down
7 changes: 2 additions & 5 deletions VSharp.ML.GameServer/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,15 @@ type Feedback =

[<Struct>]
type GameMap =
val Id: uint
val StepsToPlay: uint<step>
val StepsToStart: uint<step>
[<JsonConverter(typeof<JsonStringEnumConverter>)>]
val DefaultSearcher: searcher
val AssemblyFullName: string
val NameOfObjectToCover: string
val MapName: string
new (id, stepsToPlay, stepsToStart, assembly, defaultSearcher, objectToCover) =
new (stepsToPlay, stepsToStart, assembly, defaultSearcher, objectToCover) =
{
Id = id
StepsToPlay = stepsToPlay
StepsToStart = stepsToStart
AssemblyFullName = assembly
Expand All @@ -193,9 +191,8 @@ type GameMap =
}

[<JsonConstructor>]
new (id, stepsToPlay, stepsToStart, assemblyFullName, defaultSearcher, nameOfObjectToCover, mapName) =
new (stepsToPlay, stepsToStart, assemblyFullName, defaultSearcher, nameOfObjectToCover, mapName) =
{
Id = id
StepsToPlay = stepsToPlay
StepsToStart = stepsToStart
AssemblyFullName = assemblyFullName
Expand Down

0 comments on commit 387e5e1

Please sign in to comment.