-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcurrentgamemodel.go
105 lines (89 loc) · 3.24 KB
/
concurrentgamemodel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
concurrentgamemodel.go
Description:
Basic implementation of a Concurrent Game Model discussed Game-Theoretic Semantics for Alternating-Time Temporal Logic.
*/
package modelchecking
type ConcurrentGameModel struct {
Agents []CGMAgent
St []CGMState
Pi []AtomicProposition
Act []string // Actions
d map[CGMAgent]map[CGMState][]string //Permitted Actions (Action Function)
o map[CGMState]map[string]CGMState //Transition Function
v map[AtomicProposition][]CGMState // Valuation Function
}
type CGMAgent struct {
Name string
ParentGame *ConcurrentGameModel
}
type CGMState struct {
Name string
ParentGame *ConcurrentGameModel
}
// Atomic Proposition Already Defined
/*
Functions
*/
func CreateConcurrentGameModel(agentNames []string, stateNames []string, atomicPropositionNames []string, actionNames []string, actionFunction map[string]map[string][]string, transitionFunction map[string]map[string]string, valuationFunction map[string][]string) (ConcurrentGameModel, error) {
//Create Empty CGM To Start
cgm := ConcurrentGameModel{
Act: actionNames,
}
//Create Each Agent.
var cgmAgents []CGMAgent
for _, name := range agentNames {
cgmAgents = append(cgmAgents, CGMAgent{Name: name, ParentGame: &cgm})
}
cgm.Agents = cgmAgents
//Create Concurrent Game Model States
var cgmStates []CGMState
for _, name := range stateNames {
cgmStates = append(cgmStates, CGMState{Name: name, ParentGame: &cgm})
}
cgm.St = cgmStates
// Create Atomic Propositions
var cgmAPs []AtomicProposition
for _, name := range atomicPropositionNames {
cgmAPs = append(cgmAPs, AtomicProposition{Name: name})
}
cgm.Pi = cgmAPs
// // Create Actions
// cgm.Act = actionNames
// Create Permitted Action Sets
permittedActionMap := make(map[CGMAgent]map[CGMState][]string)
for tempAgentName, stateMap := range actionFunction {
tempAgent := CGMAgent{Name: tempAgentName, ParentGame: &cgm}
tempCGMStateMap := make(map[CGMState][]string)
for tempStateName, subsetOfActions := range stateMap {
tempState := CGMState{Name: tempStateName, ParentGame: &cgm}
tempCGMStateMap[tempState] = subsetOfActions
}
permittedActionMap[tempAgent] = tempCGMStateMap
}
cgm.d = permittedActionMap
// Create Transition Function based ON Joint Actions
tempTransitionFunction := make(map[CGMState]map[string]CGMState)
for tempStateName, jointActionMap := range transitionFunction {
tempState := CGMState{Name: tempStateName, ParentGame: &cgm}
tempJointActionMap := make(map[string]CGMState)
for jointAction, successorStateName := range jointActionMap {
tempJointActionMap[jointAction] = CGMState{Name: successorStateName, ParentGame: &cgm}
}
tempTransitionFunction[tempState] = tempJointActionMap
}
cgm.o = tempTransitionFunction
// Create Valuation Function
tempValuationFunction := make(map[AtomicProposition][]CGMState)
for apName, cgmStateNames := range valuationFunction {
tempAP := AtomicProposition{Name: apName}
var tempCGMStates []CGMState
for _, cgmStateName := range cgmStateNames {
tempCGMStates = append(tempCGMStates, CGMState{Name: cgmStateName, ParentGame: &cgm})
}
tempValuationFunction[tempAP] = tempCGMStates
}
cgm.v = tempValuationFunction
//transitionFunction
return cgm, nil
}