program 2/lib/frontend.js
/**
  * @description parse the incoming knowledgebase file
  */
@description parse the incoming knowledgebase file
@description parse the incoming knowledgebase file
function parseIncomingDataFile(inputData) {
    var a,row,input = {};
    input.arcs = []
    input.goal = []
    input.locations = inputData.shift().trim().split(' ') 
    input.items = inputData.shift().trim().split(' ') 
    input.trucks = inputData.shift().trim().split(' ') 
    input.timeLimit = +inputData.shift() 
    inputData.shift() 
    input.startState = []
    while (a = inputData.shift(), a != "GOAL") {
      row = a.trim().split(' ');
      if (input.trucks.indexOf(row[0]) !== -1 || input.items.indexOf(row[0]) !== -1) {
        input.startState.push(row);
      } else {
        input.arcs.push(a.trim());
      }
    }
    while (a = inputData.shift()) {
      input.goal.push( a.trim().split(' ') );
    }
    input.arcs = input.arcs.reduce(function(arr, arc) {
      var tail;
      arc = arc.split(' ');
      tail = arc.shift();
      arc.forEach(function(head) {
        arr.push([tail, head]);
      });
      return arr;
    }, []);
    return input;
  }
function parseIncomingDataFile ( inputData ) { var a , row , input = { } ; input . arcs = [ ] input . goal = [ ] input . locations = inputData . shift ( ) . trim ( ) . split ( ' ' ) input . items = inputData . shift ( ) . trim ( ) . split ( ' ' ) input . trucks = inputData . shift ( ) . trim ( ) . split ( ' ' ) input . timeLimit = + inputData . shift ( ) inputData . shift ( ) input . startState = [ ] while ( a = inputData . shift ( ) , a != "GOAL" ) { row = a . trim ( ) . split ( ' ' ) ; if ( input . trucks . indexOf ( row [ 0 ] ) !== - 1 || input . items . indexOf ( row [ 0 ] ) !== - 1 ) { input . startState . push ( row ) ; } else { input . arcs . push ( a . trim ( ) ) ; } } while ( a = inputData . shift ( ) ) { input . goal . push ( a . trim ( ) . split ( ' ' ) ) ; } input . arcs = input . arcs . reduce ( function ( arr , arc ) { var tail ; arc = arc . split ( ' ' ) ; tail = arc . shift ( ) ; arc . forEach ( function ( head ) { arr . push ( [ tail , head ] ) ; } ) ; return arr ; } , [ ] ) ; return input ; }
@description parse the incoming knowledgebase file
@description parse the incoming knowledgebase file
// line 0 // line 1 // line 2 // line 3 //START // loop through the remainder of the file; stop if we've hit the goal state // these are pairs of either trucks/locations or items/locations  // don't split the arcs; we'll fix them up later // we've made it into the 'GOAL' section, push in the remainder of the goal states // the arcs may come in triples or tuples. If it's a triple, split it up into in/out arc tuples // a b c => (a,b),(a,c)