Class: PgVerify::Model::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/pg-verify/model/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, components: [], variables: VariableSet.new(), specification: Specification.empty(), hazards: []) ⇒ Graph

Returns a new instance of Graph.



23
24
25
26
27
28
# File 'lib/pg-verify/model/graph.rb', line 23

def initialize(name, components: [], variables: VariableSet.new(), specification: Specification.empty(), hazards: [])
    raise "Not a variable set #{variables}" unless variables.is_a?(VariableSet)
    raise "Not a specification #{specification}" unless specification.is_a?(Specification)
    @name = name
    @components, @variables, @specification, @hazards = components, variables, specification, hazards
end

Instance Attribute Details

#componentsObject

All Model::Component’s which are part of this graph



11
12
13
# File 'lib/pg-verify/model/graph.rb', line 11

def components
  @components
end

#hazardsObject

An array of Model::Hazards for this graph



21
22
23
# File 'lib/pg-verify/model/graph.rb', line 21

def hazards
  @hazards
end

#nameObject

The name of this graph



8
9
10
# File 'lib/pg-verify/model/graph.rb', line 8

def name
  @name
end

#specificationObject

The Model::Specification of this graph



18
19
20
# File 'lib/pg-verify/model/graph.rb', line 18

def specification
  @specification
end

#variablesObject

A Model::VariableSet of all non-state variables declared by components in this graph



15
16
17
# File 'lib/pg-verify/model/graph.rb', line 15

def variables
  @variables
end

Instance Method Details

#all_variablesObject

Returns all variables used in this graph including state variables



41
42
43
# File 'lib/pg-verify/model/graph.rb', line 41

def all_variables()
    return state_variables() + @variables
end

#fault_componentsObject



45
46
47
# File 'lib/pg-verify/model/graph.rb', line 45

def fault_components()
    return @components.select(&:represents_fault?)
end

#state_variablesObject

Returns a list of state variables for each component in this graph Each state variable is named according to the component it represents and has a range consisting of the states of that component



33
34
35
36
37
38
# File 'lib/pg-verify/model/graph.rb', line 33

def state_variables()
    vars = @components.map { |cmp|
        Variable.new(cmp.name, cmp.states, cmp.name, cmp.source_location)
    }
    return VariableSet.new(*vars)
end

#validateObject



49
50
51
52
53
# File 'lib/pg-verify/model/graph.rb', line 49

def validate()
    errors = []
    errors += UnkownVariableValidation.validate(self)
    return errors
end