You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.8 KiB

  1. #include "PrismFormulaPrinter.h"
  2. #include <map>
  3. #include <string>
  4. std::string cellToConjunction(const AgentName &agentName, const cell &c) {
  5. return "x" + agentName + "=" + std::to_string(c.column) + "&y" + agentName + "=" + std::to_string(c.row);
  6. }
  7. namespace prism {
  8. PrismFormulaPrinter::PrismFormulaPrinter() {}
  9. std::ostream& PrismFormulaPrinter::printRestrictionFormula(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &grid_cells) {
  10. os << buildFormula(agentName + "CannotMove" + direction, buildDisjunction(agentName, grid_cells));
  11. return os;
  12. }
  13. std::ostream& PrismFormulaPrinter::printRestrictionFormulaWithCondition(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &grid_cells, const std::vector<std::string> conditions) {
  14. os << buildFormula(agentName + "Something", buildDisjunction(agentName, grid_cells, conditions));
  15. return os;
  16. }
  17. std::string PrismFormulaPrinter::buildFormula(const std::string &formulaName, const std::string &formula) {
  18. return "formula " + formulaName + " = " + formula + ";\n";
  19. }
  20. std::string PrismFormulaPrinter::buildDisjunction(const AgentName &agentName, const cells &cells, const std::vector<std::string> &conditions) {
  21. bool first = true;
  22. std::string disjunction = "";
  23. if(!conditions.empty()) {
  24. for(uint index = 0; index < cells.size(); index++) {
  25. if(first) first = false;
  26. else disjunction += " | ";
  27. disjunction += "(" + cellToConjunction(agentName, cells.at(index)) + "&" + conditions.at(index) + ")";
  28. }
  29. } else {
  30. for(auto const cell : cells) {
  31. if(first) first = false;
  32. else disjunction += " | ";
  33. disjunction += "(" + cellToConjunction(agentName, cell) + ")";
  34. }
  35. }
  36. return disjunction;
  37. }
  38. }