Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions VSharp.Explorer/AISearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,27 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingMode: Option<AIAgentTrai

Application.applicationGraphDelta.Clear()

if aiMode <> Runner && stepsToPlay = stepsPlayed then
let toPredict =
match aiMode with
| TrainingSendEachStep
| TrainingSendModel ->
if stepsPlayed > 0u<step> then
gameStateDelta
else
gameState.Value
| Runner -> gameState.Value

let stateId = oracle.Predict toPredict
afterFirstAIPeek <- true
let state = availableStates |> Seq.tryFind (fun s -> s.internalId = stateId)
lastCollectedStatistics <- statistics

match state with
| Some state -> Some state
| None ->
incorrectPredictedStateId <- true
oracle.Feedback(Feedback.IncorrectPredictedStateId stateId)
None
else
let toPredict =
match aiMode with
| TrainingSendEachStep
| TrainingSendModel ->
if stepsPlayed > 0u<step> then
gameStateDelta
else
gameState.Value
| Runner -> gameState.Value

let stateId = oracle.Predict toPredict

afterFirstAIPeek <- true
let state = availableStates |> Seq.tryFind (fun s -> s.internalId = stateId)
lastCollectedStatistics <- statistics
stepsPlayed <- stepsPlayed + 1u<step>

match state with
| Some state -> Some state
| None ->
incorrectPredictedStateId <- true
oracle.Feedback(Feedback.IncorrectPredictedStateId stateId)
None

static member updateGameState (delta: GameState) (gameState: Option<GameState>) =
match gameState with
Expand Down Expand Up @@ -185,7 +180,7 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingMode: Option<AIAgentTrai
State(
s.Id,
s.Position,
s.PathCondition,
s.PathConditionSize,
s.VisitedAgainVertices,
s.VisitedNotCoveredVerticesInZone,
s.VisitedNotCoveredVerticesOutOfZone,
Expand Down Expand Up @@ -388,7 +383,7 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingMode: Option<AIAgentTrai
firstFreePositionInParentsOf <- firstFreePositionInParentsOf + state.Children.Length

index_pcToState.[firstFreePositionInPcToState] <-
int64 pathConditionVerticesIds[state.PathCondition.Id]
int64 pathConditionVerticesIds[state.PathConditionSize.Id]

index_pcToState.[firstFreePositionInPcToState + gameState.States.Length] <-
int64 stateIds[state.Id]
Expand Down
1 change: 1 addition & 0 deletions VSharp.ML.GameServer.Runner/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ let ws port outputDirectory (webSocket: WebSocket) (context: HttpContext) =
GameOver(
explorationResult.ActualCoverage,
explorationResult.TestsCount,
explorationResult.StepsCount,
explorationResult.ErrorsCount
)
)
Expand Down
14 changes: 8 additions & 6 deletions VSharp.ML.GameServer/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ type GameOverMessageBody =
interface IRawOutgoingMessageBody
val ActualCoverage: uint<percent>
val TestsCount: uint32<test>
val StepsCount: uint32<step>
val ErrorsCount: uint32<error>

new(actualCoverage, testsCount, errorsCount) =
new(actualCoverage, testsCount, stepsCount, errorsCount) =
{ ActualCoverage = actualCoverage
TestsCount = testsCount
StepsCount = stepsCount
ErrorsCount = errorsCount }

[<Struct>]
Expand Down Expand Up @@ -151,7 +153,7 @@ type StateHistoryElem =
type State =
val Id: uint<stateId>
val Position: uint<byte_offset> // to basic block id
val PathCondition: PathConditionVertex
val PathConditionSize: PathConditionVertex
val VisitedAgainVertices: uint
val VisitedNotCoveredVerticesInZone: uint
val VisitedNotCoveredVerticesOutOfZone: uint
Expand All @@ -175,7 +177,7 @@ type State =
) =
{ Id = id
Position = position
PathCondition = pathCondition
PathConditionSize = pathCondition
VisitedAgainVertices = visitedAgainVertices
VisitedNotCoveredVerticesInZone = visitedNotCoveredVerticesInZone
VisitedNotCoveredVerticesOutOfZone = visitedNotCoveredVerticesOutOfZone
Expand Down Expand Up @@ -371,7 +373,7 @@ type IncorrectPredictedStateIdMessageBody =
new(stateId) = { StateId = stateId }

type OutgoingMessage =
| GameOver of uint<percent> * uint32<test> * uint32<error>
| GameOver of uint<percent> * uint32<test> * uint32<step> * uint32<error>
| MoveReward of Reward
| IncorrectPredictedStateId of uint<stateId>
| ReadyForNextStep of GameState
Expand All @@ -397,8 +399,8 @@ let deserializeInputMessage (messageData: byte[]) =

let serializeOutgoingMessage (message: OutgoingMessage) =
match message with
| GameOver(actualCoverage, testsCount, errorsCount) ->
RawOutgoingMessage("GameOver", box (GameOverMessageBody(actualCoverage, testsCount, errorsCount)))
| GameOver(actualCoverage, testsCount, stepsCount, errorsCount) ->
RawOutgoingMessage("GameOver", box (GameOverMessageBody(actualCoverage, testsCount, stepsCount, errorsCount)))
| MoveReward reward -> RawOutgoingMessage("MoveReward", reward)
| IncorrectPredictedStateId stateId ->
RawOutgoingMessage("IncorrectPredictedStateId", IncorrectPredictedStateIdMessageBody stateId)
Expand Down
Loading