Variable.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.cast_de_nrw_schule_svws_core_kursblockung_satsolver_Variable = exports.Variable = void 0;
  4. const JavaObject_1 = require("../../../java/lang/JavaObject");
  5. const LinkedCollection_1 = require("../../../core/adt/collection/LinkedCollection");
  6. class Variable extends JavaObject_1.JavaObject {
  7. nr;
  8. statSatFree;
  9. clauses;
  10. neighbours;
  11. index = 0;
  12. negation = null;
  13. /**
  14. * Konstruktor. Erzeugt eine neue Variable mit einer bestimmten Variablen-Nummer
  15. * (ungleich 0).
  16. *
  17. * @param pNr Die Nummer der Variablen (ungleich 0).
  18. */
  19. constructor(pNr) {
  20. super();
  21. this.nr = pNr;
  22. this.statSatFree = [...Array(4)].map(e => Array(4).fill(0));
  23. this.clauses = new LinkedCollection_1.LinkedCollection();
  24. this.neighbours = new LinkedCollection_1.LinkedCollection();
  25. this.index = -3;
  26. this.negation = null;
  27. }
  28. toString() {
  29. return "" + this.nr;
  30. }
  31. /**
  32. * Überprüft, ob diese Variable noch auf TRUE gesetzt werden kann.
  33. *
  34. * @return TRUE, falls man diese Variable und einen logischen Widerspruch
  35. * erfüllen kann.
  36. */
  37. isUnsat() {
  38. if (this.statSatFree[0][0] > 0) {
  39. console.log(JSON.stringify("FEHLER: Dieser Fall darf gar nicht passieren."));
  40. return true;
  41. }
  42. if ((this.negation !== null) && (this.negation.statSatFree[0][1] > 0)) {
  43. return true;
  44. }
  45. return false;
  46. }
  47. /**
  48. * Vergleicht die Statistik zweier Variablen und bestimmt, für welche man sich
  49. * entscheiden sollte.
  50. *
  51. * @param b Die Variable, mit der verglichen werden soll.
  52. *
  53. * @return TRUE, wenn diese Instanz besser als "b" ist.
  54. */
  55. isBetterThan(b) {
  56. let statB = b.statSatFree;
  57. if (this.statSatFree[0][0] > statB[0][0])
  58. return true;
  59. if (this.statSatFree[0][0] < statB[0][0])
  60. return false;
  61. if (this.statSatFree[0][1] > statB[0][1])
  62. return true;
  63. if (this.statSatFree[0][1] < statB[0][1])
  64. return false;
  65. if (this.statSatFree[0][2] > statB[0][2])
  66. return true;
  67. if (this.statSatFree[0][2] < statB[0][2])
  68. return false;
  69. if (this.statSatFree[0][3] > statB[0][3])
  70. return true;
  71. if (this.statSatFree[0][3] < statB[0][3])
  72. return false;
  73. return Math.random() < 0.5;
  74. }
  75. /**
  76. * Debug-Ausgabe. Nur für Testzwecke.
  77. */
  78. debug() {
  79. console.log(JSON.stringify("DEBUGGING VAR " + this.nr));
  80. for (let r = 0; r < this.statSatFree.length; r++) {
  81. for (let c = 0; c < this.statSatFree[r].length; c++) {
  82. console.log(JSON.stringify(" " + this.statSatFree[r][c]));
  83. }
  84. console.log(JSON.stringify(" "));
  85. if (this.negation !== null) {
  86. for (let c = 0; c < this.negation.statSatFree[r].length; c++) {
  87. console.log(JSON.stringify(" " + this.negation.statSatFree[r][c]));
  88. }
  89. }
  90. console.log();
  91. }
  92. }
  93. /**
  94. * Liefert die Anzahl an noch nicht erfüllten Klauseln.
  95. *
  96. * @return Die Anzahl an noch nicht erfüllten Klauseln.
  97. */
  98. getClauseOccurences() {
  99. let sum = 0;
  100. for (let free = 0; free < 4; free++) {
  101. sum += this.statSatFree[0][free];
  102. }
  103. return sum;
  104. }
  105. isTranspiledInstanceOf(name) {
  106. return ['de.nrw.schule.svws.core.kursblockung.satsolver.Variable'].includes(name);
  107. }
  108. }
  109. exports.Variable = Variable;
  110. function cast_de_nrw_schule_svws_core_kursblockung_satsolver_Variable(obj) {
  111. return obj;
  112. }
  113. exports.cast_de_nrw_schule_svws_core_kursblockung_satsolver_Variable = cast_de_nrw_schule_svws_core_kursblockung_satsolver_Variable;
  114. //# sourceMappingURL=Variable.js.map