aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/xtend-gen/ca/mcgill/ecse/dslreasoner/vampire/reasoner/VampireSolver.java
blob: 3e3bd6881a72ade8a7e7483ab65ad922296cc235 (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package ca.mcgill.ecse.dslreasoner.vampire.reasoner;

import ca.mcgill.ecse.dslreasoner.VampireLanguageStandaloneSetup;
import ca.mcgill.ecse.dslreasoner.VampireLanguageStandaloneSetupGenerated;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.VampireSolverConfiguration;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder.Logic2VampireLanguageMapper;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder.Logic2VampireLanguageMapperTrace;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder.Logic2VampireLanguageMapper_Support;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder.MonitoredVampireSolution;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder.Vampire2LogicMapper;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder.VampireHandler;
import ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder.VampireModelInterpretation;
import ca.mcgill.ecse.dslreasoner.vampireLanguage.VampireLanguageFactory;
import ca.mcgill.ecse.dslreasoner.vampireLanguage.VampireLanguagePackage;
import ca.mcgill.ecse.dslreasoner.vampireLanguage.VampireModel;
import com.google.common.base.Objects;
import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel;
import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation;
import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner;
import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasonerException;
import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration;
import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput;
import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem;
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult;
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicresultFactory;
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult;
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.RealStatisticEntry;
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.StatisticEntry;
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.Statistics;
import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.StringStatisticEntry;
import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@SuppressWarnings("all")
public class VampireSolver extends LogicReasoner {
  public VampireSolver() {
    VampireLanguagePackage.eINSTANCE.eClass();
    final VampireLanguageStandaloneSetupGenerated x = new VampireLanguageStandaloneSetupGenerated();
    VampireLanguageStandaloneSetup.doSetup();
  }
  
  private final Logic2VampireLanguageMapper forwardMapper = new Logic2VampireLanguageMapper();
  
  private final Vampire2LogicMapper backwardMapper = new Vampire2LogicMapper();
  
  private final VampireHandler handler = new VampireHandler();
  
  private final Logic2VampireLanguageMapper_Support support = new Logic2VampireLanguageMapper_Support();
  
  @Extension
  private final LogicresultFactory resultFactory = LogicresultFactory.eINSTANCE;
  
  @Extension
  private final VampireLanguageFactory factory = VampireLanguageFactory.eINSTANCE;
  
  @Override
  public LogicResult solve(final LogicProblem problem, final LogicSolverConfiguration config, final ReasonerWorkspace workspace) throws LogicReasonerException {
    try {
      final VampireSolverConfiguration vampireConfig = this.asConfig(config);
      String fileName = (((("problem_" + Integer.valueOf(vampireConfig.typeScopes.minNewElements)) + "-") + 
        Integer.valueOf(vampireConfig.typeScopes.maxNewElements)) + ".tptp");
      final long transformationStart = System.currentTimeMillis();
      final TracedOutput<VampireModel, Logic2VampireLanguageMapperTrace> result = this.forwardMapper.transformProblem(problem, vampireConfig);
      long _currentTimeMillis = System.currentTimeMillis();
      final long transformationTime = (_currentTimeMillis - transformationStart);
      final VampireModel vampireProblem = result.getOutput();
      final Logic2VampireLanguageMapperTrace forwardTrace = result.getTrace();
      String fileURI = null;
      String vampireCode = null;
      vampireCode = workspace.writeModelToString(vampireProblem, fileName);
      final boolean writeFile = ((vampireConfig.documentationLevel == DocumentationLevel.NORMAL) || 
        (vampireConfig.documentationLevel == DocumentationLevel.FULL));
      if (writeFile) {
        fileURI = workspace.writeModel(vampireProblem, fileName).toFileString();
      }
      if (vampireConfig.genModel) {
        if (vampireConfig.server) {
          final String form = this.support.makeForm(vampireCode, vampireConfig.solver, vampireConfig.runtimeLimit);
          ArrayList<String> response = CollectionLiterals.<String>newArrayList();
          int ind = 0;
          boolean done = false;
          InputOutput.<String>print(" ");
          while ((!done)) {
            {
              InputOutput.<String>print("(x)");
              done = false;
              response = this.support.sendPost(form);
              boolean responseFound = false;
              ind = 0;
              while ((!responseFound)) {
                {
                  String line = response.get(ind);
                  if (((line.length() >= 5) && Objects.equal(line.substring(0, 5), "ERROR"))) {
                    done = false;
                    responseFound = true;
                  } else {
                    boolean _equals = Objects.equal(line, "</PRE>");
                    if (_equals) {
                      done = true;
                      responseFound = true;
                    }
                  }
                  ind++;
                }
              }
            }
          }
          final String satRaw = response.get((ind - 3));
          final String modRaw = response.get((ind - 2));
          final ArrayList<String> sat = CollectionLiterals.<String>newArrayList(satRaw.split(" "));
          final ArrayList<String> mod = CollectionLiterals.<String>newArrayList(modRaw.split(" "));
          final String satOut = sat.get(1);
          final String modOut = mod.get(1);
          final String satTime = sat.get(2);
          final String modTime = mod.get(2);
          InputOutput.println();
          InputOutput.<ArrayList<String>>println(sat);
          InputOutput.<ArrayList<String>>println(mod);
          ModelResult _createModelResult = this.resultFactory.createModelResult();
          final Procedure1<ModelResult> _function = (ModelResult it) -> {
            it.setProblem(null);
            EList<Object> _representation = it.getRepresentation();
            VampireModel _createVampireModel = this.factory.createVampireModel();
            final Procedure1<VampireModel> _function_1 = (VampireModel it_1) -> {
            };
            VampireModel _doubleArrow = ObjectExtensions.<VampireModel>operator_doubleArrow(_createVampireModel, _function_1);
            _representation.add(_doubleArrow);
            it.setTrace(it.getTrace());
            Statistics _createStatistics = this.resultFactory.createStatistics();
            final Procedure1<Statistics> _function_2 = (Statistics it_1) -> {
              it_1.setTransformationTime(((int) transformationTime));
              EList<StatisticEntry> _entries = it_1.getEntries();
              StringStatisticEntry _createStringStatisticEntry = this.resultFactory.createStringStatisticEntry();
              final Procedure1<StringStatisticEntry> _function_3 = (StringStatisticEntry it_2) -> {
                it_2.setName("satOut");
                it_2.setValue(satOut);
              };
              StringStatisticEntry _doubleArrow_1 = ObjectExtensions.<StringStatisticEntry>operator_doubleArrow(_createStringStatisticEntry, _function_3);
              _entries.add(_doubleArrow_1);
              EList<StatisticEntry> _entries_1 = it_1.getEntries();
              RealStatisticEntry _createRealStatisticEntry = this.resultFactory.createRealStatisticEntry();
              final Procedure1<RealStatisticEntry> _function_4 = (RealStatisticEntry it_2) -> {
                it_2.setName("satTime");
                it_2.setValue(Double.parseDouble(satTime));
              };
              RealStatisticEntry _doubleArrow_2 = ObjectExtensions.<RealStatisticEntry>operator_doubleArrow(_createRealStatisticEntry, _function_4);
              _entries_1.add(_doubleArrow_2);
              EList<StatisticEntry> _entries_2 = it_1.getEntries();
              StringStatisticEntry _createStringStatisticEntry_1 = this.resultFactory.createStringStatisticEntry();
              final Procedure1<StringStatisticEntry> _function_5 = (StringStatisticEntry it_2) -> {
                it_2.setName("modOut");
                it_2.setValue(modOut);
              };
              StringStatisticEntry _doubleArrow_3 = ObjectExtensions.<StringStatisticEntry>operator_doubleArrow(_createStringStatisticEntry_1, _function_5);
              _entries_2.add(_doubleArrow_3);
              EList<StatisticEntry> _entries_3 = it_1.getEntries();
              RealStatisticEntry _createRealStatisticEntry_1 = this.resultFactory.createRealStatisticEntry();
              final Procedure1<RealStatisticEntry> _function_6 = (RealStatisticEntry it_2) -> {
                it_2.setName("modTime");
                it_2.setValue(Double.parseDouble(modTime));
              };
              RealStatisticEntry _doubleArrow_4 = ObjectExtensions.<RealStatisticEntry>operator_doubleArrow(_createRealStatisticEntry_1, _function_6);
              _entries_3.add(_doubleArrow_4);
            };
            Statistics _doubleArrow_1 = ObjectExtensions.<Statistics>operator_doubleArrow(_createStatistics, _function_2);
            it.setStatistics(_doubleArrow_1);
          };
          return ObjectExtensions.<ModelResult>operator_doubleArrow(_createModelResult, _function);
        } else {
          final MonitoredVampireSolution vampSol = this.handler.callSolver(vampireProblem, workspace, vampireConfig);
          final long backTransformationStart = System.currentTimeMillis();
          final ModelResult logicResult = this.backwardMapper.transformOutput(problem, 
            vampireConfig.solutionScope.numberOfRequiredSolution, vampSol, forwardTrace, transformationTime);
          long _currentTimeMillis_1 = System.currentTimeMillis();
          final long backTransformationTime = (_currentTimeMillis_1 - backTransformationStart);
          return logicResult;
        }
      }
      MonitoredVampireSolution _monitoredVampireSolution = new MonitoredVampireSolution((-1), null);
      return this.backwardMapper.transformOutput(problem, vampireConfig.solutionScope.numberOfRequiredSolution, _monitoredVampireSolution, forwardTrace, transformationTime);
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  public VampireSolverConfiguration asConfig(final LogicSolverConfiguration configuration) {
    if ((configuration instanceof VampireSolverConfiguration)) {
      return ((VampireSolverConfiguration)configuration);
    } else {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("The configuration have to be an ");
      String _simpleName = VampireSolverConfiguration.class.getSimpleName();
      _builder.append(_simpleName);
      _builder.append("!");
      throw new IllegalArgumentException(_builder.toString());
    }
  }
  
  @Override
  public List<? extends LogicModelInterpretation> getInterpretations(final ModelResult modelResult) {
    List<VampireModelInterpretation> _xblockexpression = null;
    {
      final EList<Object> sols = modelResult.getRepresentation();
      final Function1<Object, VampireModelInterpretation> _function = (Object it) -> {
        Object _trace = modelResult.getTrace();
        return new VampireModelInterpretation(
          ((VampireModel) it), 
          ((Logic2VampireLanguageMapperTrace) _trace));
      };
      _xblockexpression = ListExtensions.<Object, VampireModelInterpretation>map(sols, _function);
    }
    return _xblockexpression;
  }
}