Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fileName = "";
  2.  
  3. const fs = require('fs');
  4.  
  5. function readFormula(fileName) {
  6.  
  7.     let text = fs.readFileSync(fileName, 'utf8').split("\n")//  an array containing lines of text extracted from the file.
  8.  
  9.     let qtVariables = 0;
  10.     let qtClauses = 0;
  11.     let lineOfClauses = "";
  12.  
  13.     for (let i = 0; i < text.length; i++) {
  14.  
  15.         let firstChar = text[i].charAt(0);
  16.  
  17.         if (firstChar == "c"){
  18.             //does NOTHING
  19.         } else if(firstChar == "p") {
  20.             //  coloca cada elemento da linha em pos.
  21.             let pos = text[i].split(" ");
  22.  
  23.             // determina como inteiro a quantidade de variaveis e clausulas.
  24.  
  25.             qtVariables = parseInt(pos[2]);
  26.             qtClauses = parseInt(pos[3]);
  27.  
  28.         } else {
  29.             lineOfClauses = lineOfClauses.concat(" ", text[i]);
  30.         };
  31.  
  32.         let clauseLine = lineOfClauses.split("0");
  33.     };
  34.  
  35.  
  36.  
  37.     let clauses = readClauses(clauseLine)
  38.     let variables = readVariables(clauses)
  39.  
  40.     // In the following line, text is passed as an argument so that the function
  41.     // is able to extract the problem specification.
  42.  
  43.     let specOk = checkProblemSpecification(text, clauses, variables)
  44.  
  45.     let result = { 'clauses': [], 'variables': [] }
  46.     if (specOk) {
  47.         result.clauses = clauses
  48.         result.variables = variables
  49.     }
  50.     return result
  51. }
  52.  
  53. function readClauses (clauseLine){
  54.  
  55.     let clauses = [];
  56.  
  57.     for (let i = 0; i < clauseLine.length; i++) {
  58.  
  59.  
  60.         let eachVariable = clauseLine[i].split(" ");
  61.  
  62.  
  63.         for (let j = 0; j < eachVariable.length; j++){
  64.  
  65.             if (eachVariable[j] != ""){
  66.                 eachVariable.push(parseInt(eachVariable[j], 10));
  67.             };
  68.  
  69.         };
  70.  
  71.         clauses.push(eachVariable);
  72.     };
  73.  
  74.     return clauses;
  75.  
  76. }
  77.  
  78. function readVariables(qntVariables){
  79.  
  80.     let allZeros = [];
  81.  
  82.     for (let i = 0; i < qntVariables; i++){
  83.  
  84.         allZeros.push("0");
  85.  
  86.     };
  87.  
  88.     return allZeros;
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement