@@ -86,8 +86,7 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
8686 s.Children |> Array.filter activeStates.Contains
8787 ))
8888
89- let pathConditionVertices =
90- ResizeArray< PathConditionVertex> s.PathConditionVertices
89+ let pathConditionVertices = ResizeArray< PathConditionVertex> s.PathConditionVertices
9190
9291 pathConditionVertices.AddRange delta.PathConditionVertices
9392
@@ -182,7 +181,8 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
182181
183182 new ( pathToONNX: string, useGPU: bool, optimize: bool) =
184183 let numOfVertexAttributes = 7
185- let numOfStateAttributes = 7
184+ let numOfStateAttributes = 6
185+ let numOfPathConditionVertexAttributes = 49
186186 let numOfHistoryEdgeAttributes = 2
187187
188188 let createOracle ( pathToONNX : string ) =
@@ -205,10 +205,33 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
205205 let predict ( gameState : GameState ) =
206206 let stateIds = Dictionary< uint< stateId>, int>()
207207 let verticesIds = Dictionary< uint< basicBlockGlobalId>, int>()
208+ let pathConditionVerticesIds = Dictionary< uint< pathConditionVertexId>, int>()
208209
209210 let networkInput =
210211 let res = Dictionary<_, _>()
211212
213+ let pathConditionVertices , numOfPcToPcEdges =
214+ let mutable numOfPcToPcEdges = 0
215+
216+ let shape =
217+ [| int64 gameState.PathConditionVertices.Length
218+ numOfPathConditionVertexAttributes |]
219+
220+ let attributes =
221+ Array.zeroCreate (
222+ gameState.PathConditionVertices.Length * numOfPathConditionVertexAttributes
223+ )
224+
225+ for i in 0 .. gameState.PathConditionVertices.Length - 1 do
226+ let v = gameState.PathConditionVertices.[ i]
227+ numOfPcToPcEdges <- numOfPcToPcEdges + v.Children.Length * 2
228+ pathConditionVerticesIds.Add( v.Id, i)
229+ let j = i * numOfPathConditionVertexAttributes
230+ attributes.[ j + int v.Type] <- float32 1 u
231+
232+ OrtValue.CreateTensorValueFromMemory( attributes, shape), numOfPcToPcEdges
233+
234+
212235 let gameVertices =
213236 let shape = [| int64 gameState.GraphVertices.Length; numOfVertexAttributes |]
214237
@@ -243,7 +266,7 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
243266 let j = i * numOfStateAttributes
244267 attributes.[ j] <- float32 v.Position
245268 // TODO: Support path condition
246- // attributes.[j + 1] <- float32 v.PathConditionSize
269+ // attributes.[j + 1] <- float32 v.PathConditionSize
247270 attributes.[ j + 2 ] <- float32 v.VisitedAgainVertices
248271 attributes.[ j + 3 ] <- float32 v.VisitedNotCoveredVerticesInZone
249272 attributes.[ j + 4 ] <- float32 v.VisitedNotCoveredVerticesOutOfZone
@@ -252,6 +275,31 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
252275
253276 OrtValue.CreateTensorValueFromMemory( attributes, shape), numOfParentOfEdges, numOfHistoryEdges
254277
278+ let pcToPcEdgeIndex =
279+ let shapeOfIndex = [| 2 L; numOfPcToPcEdges |]
280+ let index = Array.zeroCreate ( 2 * numOfPcToPcEdges)
281+ let mutable firstFreePositionOfIndex = 0
282+
283+ for v in gameState.PathConditionVertices do
284+ for child in v.Children do
285+ // from vertex to child
286+ index.[ firstFreePositionOfIndex] <- pathConditionVerticesIds.[ v.Id]
287+
288+ index.[ firstFreePositionOfIndex + 2 * numOfPcToPcEdges] <-
289+ pathConditionVerticesIds.[ child]
290+
291+ firstFreePositionOfIndex <- firstFreePositionOfIndex + 1
292+ // from child to vertex
293+ index.[ firstFreePositionOfIndex] <- pathConditionVerticesIds.[ child]
294+
295+ index.[ firstFreePositionOfIndex + 2 * numOfPcToPcEdges] <-
296+ pathConditionVerticesIds.[ v.Id]
297+
298+ firstFreePositionOfIndex <- firstFreePositionOfIndex + 1
299+
300+ OrtValue.CreateTensorValueFromMemory( index, shapeOfIndex)
301+
302+
255303 let vertexToVertexEdgesIndex , vertexToVertexEdgesAttributes =
256304 let shapeOfIndex = [| 2 L; gameState.Map.Length |]
257305 let shapeOfAttributes = [| int64 gameState.Map.Length |]
@@ -267,11 +315,13 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
267315 OrtValue.CreateTensorValueFromMemory( index, shapeOfIndex),
268316 OrtValue.CreateTensorValueFromMemory( attributes, shapeOfAttributes)
269317
270- let historyEdgesIndex_vertexToState , historyEdgesAttributes , parentOfEdges =
318+ let historyEdgesIndex_vertexToState , historyEdgesAttributes , parentOfEdges , edgeIndex_pcToState =
271319 let shapeOfParentOf = [| 2 L; numOfParentOfEdges |]
272320 let parentOf = Array.zeroCreate ( 2 * numOfParentOfEdges)
273321 let shapeOfHistory = [| 2 L; numOfHistoryEdges |]
274322 let historyIndex_vertexToState = Array.zeroCreate ( 2 * numOfHistoryEdges)
323+ let shapeOfPcToState = [| 2 L; gameState.States.Length |]
324+ let index_pcToState = Array.zeroCreate ( 2 * gameState.States.Length)
275325
276326 let shapeOfHistoryAttributes =
277327 [| int64 numOfHistoryEdges; int64 numOfHistoryEdgeAttributes |]
@@ -280,6 +330,7 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
280330 let mutable firstFreePositionInParentsOf = 0
281331 let mutable firstFreePositionInHistoryIndex = 0
282332 let mutable firstFreePositionInHistoryAttributes = 0
333+ let mutable firstFreePositionInPcToState = 0
283334
284335 gameState.States
285336 |> Array.iter ( fun state ->
@@ -291,6 +342,14 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
291342
292343 firstFreePositionInParentsOf <- firstFreePositionInParentsOf + state.Children.Length
293344
345+ index_ pcToState.[ firstFreePositionInPcToState] <-
346+ int64 pathConditionVerticesIds[ state.PathCondition.Id]
347+
348+ index_ pcToState.[ firstFreePositionInPcToState + gameState.States.Length] <-
349+ int64 stateIds[ state.Id]
350+
351+ firstFreePositionInPcToState <- firstFreePositionInPcToState + 1
352+
294353 state.History
295354 |> Array.iteri ( fun i historyElem ->
296355 let j = firstFreePositionInHistoryIndex + i
@@ -309,7 +368,8 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
309368
310369 OrtValue.CreateTensorValueFromMemory( historyIndex_ vertexToState, shapeOfHistory),
311370 OrtValue.CreateTensorValueFromMemory( historyAttributes, shapeOfHistoryAttributes),
312- OrtValue.CreateTensorValueFromMemory( parentOf, shapeOfParentOf)
371+ OrtValue.CreateTensorValueFromMemory( parentOf, shapeOfParentOf),
372+ OrtValue.CreateTensorValueFromMemory( index_ pcToState, shapeOfPcToState)
313373
314374 let statePosition_stateToVertex , statePosition_vertexToState =
315375 let data_stateToVertex = Array.zeroCreate ( 2 * gameState.States.Length)
@@ -337,6 +397,7 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
337397
338398 res.Add( " game_vertex" , gameVertices)
339399 res.Add( " state_vertex" , states)
400+ res.Add( " path_condition_vertex" , pathConditionVertices)
340401
341402 res.Add( " gamevertex_to_gamevertex_index" , vertexToVertexEdgesIndex)
342403 res.Add( " gamevertex_to_gamevertex_type" , vertexToVertexEdgesAttributes)
@@ -347,6 +408,9 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingOptions: Option<AIAgentT
347408 res.Add( " gamevertex_in_statevertex" , statePosition_ vertexToState)
348409 res.Add( " statevertex_parentof_statevertex" , parentOfEdges)
349410
411+ res.Add( " pathconditionvertex_to_pathconditionvertex" , pcToPcEdgeIndex)
412+ res.Add( " pathconditionvertex_to_statevertex" , edgeIndex_ pcToState)
413+
350414 res
351415
352416 let output = session.Run( runOptions, networkInput, session.OutputNames)
0 commit comments