aboutsummaryrefslogtreecommitdiffstats
path: root/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/Ft2GalileoTransformation.java
blob: 8748825d586ec75c4b0baca1cabddc9ad2171142 (plain) (blame)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ft2galileo;

import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.AndGate;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.BasicEvent;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantDistribution;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Distribution;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ExponentialDistribution;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FaultTree;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Gate;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.KOfMGate;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.OrGate;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent;
import java.util.Arrays;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtend2.lib.StringConcatenationClient;

@SuppressWarnings("all")
public class Ft2GalileoTransformation {
  public CharSequence toGalileo(final FaultTree faultTree) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("toplevel \"");
    String _name = faultTree.getTopEvent().getName();
    _builder.append(_name);
    _builder.append("\";");
    _builder.newLineIfNotEmpty();
    {
      EList<RandomEvent> _events = faultTree.getEvents();
      for(final RandomEvent event : _events) {
        _builder.append("\"");
        String _name_1 = event.getName();
        _builder.append(_name_1);
        _builder.append("\" ");
        Object _defineEvent = this.defineEvent(event);
        _builder.append(_defineEvent);
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  protected Object _defineEvent(final BasicEvent basicEvent) {
    StringConcatenation _builder = new StringConcatenation();
    StringConcatenationClient _defineDistribution = this.defineDistribution(basicEvent.getDistribution());
    _builder.append(_defineDistribution);
    _builder.append(" dorm=0.0");
    return _builder;
  }
  
  protected StringConcatenationClient _defineDistribution(final ConstantDistribution distribution) {
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("p=");
        double _p = distribution.getP();
        _builder.append(_p);
      }
    };
    return _client;
  }
  
  protected StringConcatenationClient _defineDistribution(final ExponentialDistribution distribution) {
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("lambda=");
        double _lambda = distribution.getLambda();
        _builder.append(_lambda);
      }
    };
    return _client;
  }
  
  protected StringConcatenationClient _defineDistribution(final Distribution distribution) {
    throw new IllegalArgumentException(("Unknown distribution: " + distribution));
  }
  
  protected StringConcatenationClient _defineEvent(final Gate gate) {
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        StringConcatenationClient _defineGate = Ft2GalileoTransformation.this.defineGate(gate);
        _builder.append(_defineGate);
        _builder.append(" ");
        {
          EList<RandomEvent> _inputEvents = gate.getInputEvents();
          boolean _hasElements = false;
          for(final RandomEvent input : _inputEvents) {
            if (!_hasElements) {
              _hasElements = true;
            } else {
              _builder.appendImmediate(" ", "");
            }
            _builder.append("\"");
            String _name = input.getName();
            _builder.append(_name);
            _builder.append("\"");
          }
        }
      }
    };
    return _client;
  }
  
  protected StringConcatenationClient _defineGate(final AndGate gate) {
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("and");
      }
    };
    return _client;
  }
  
  protected StringConcatenationClient _defineGate(final OrGate gate) {
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("or");
      }
    };
    return _client;
  }
  
  protected StringConcatenationClient _defineGate(final KOfMGate gate) {
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        int _k = gate.getK();
        _builder.append(_k);
        _builder.append("of");
        int _size = gate.getInputEvents().size();
        _builder.append(_size);
      }
    };
    return _client;
  }
  
  protected StringConcatenationClient _defineGate(final Gate gate) {
    throw new IllegalArgumentException(("Unknown gate: " + gate));
  }
  
  protected StringConcatenationClient _defineEvent(final RandomEvent randomEvent) {
    throw new IllegalArgumentException(("Unknown random even: " + randomEvent));
  }
  
  protected Object defineEvent(final RandomEvent basicEvent) {
    if (basicEvent instanceof BasicEvent) {
      return _defineEvent((BasicEvent)basicEvent);
    } else if (basicEvent instanceof Gate) {
      return _defineEvent((Gate)basicEvent);
    } else if (basicEvent != null) {
      return _defineEvent(basicEvent);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(basicEvent).toString());
    }
  }
  
  protected StringConcatenationClient defineDistribution(final Distribution distribution) {
    if (distribution instanceof ConstantDistribution) {
      return _defineDistribution((ConstantDistribution)distribution);
    } else if (distribution instanceof ExponentialDistribution) {
      return _defineDistribution((ExponentialDistribution)distribution);
    } else if (distribution != null) {
      return _defineDistribution(distribution);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(distribution).toString());
    }
  }
  
  protected StringConcatenationClient defineGate(final Gate gate) {
    if (gate instanceof AndGate) {
      return _defineGate((AndGate)gate);
    } else if (gate instanceof KOfMGate) {
      return _defineGate((KOfMGate)gate);
    } else if (gate instanceof OrGate) {
      return _defineGate((OrGate)gate);
    } else if (gate != null) {
      return _defineGate(gate);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(gate).toString());
    }
  }
}