function applyPresetFilter(inputExpression, data) {
    let expression = removeOuterParentheses(inputExpression);

    // Preset filter: {presetName[orbits;instruments;numbers]}
    expression = expression.substring(1, expression.length-1);

    let flip = false;
    if (expression.startsWith('~')) {
        flip = true;
        expression = expression.substring(1, expression.length);
    }

    let numOrbits = store.state.problem.extra.orbitNum;
    let numInstruments = store.state.problem.extra.instrumentNum;
    let type = expression.split('[')[0];
    let inputs = data.inputs;

    if (type === 'paretoFront') {
        if (data.paretoRanking || data.paretoRanking === 0) {
            let rank = +data.paretoRanking;
            let arg = +expression.substring(0, expression.length-1).split('[')[1];
            return rank <= arg;
        }
    }

    let condition = expression.substring(0, expression.length-1).split('[')[1];
    let condSplit = condition.split(';');
    let orbit, instr, numb;

    orbit = condSplit[0];
    instr = condSplit[1];
    numb = condSplit[2];

    let result;
    switch (type) {

    case 'inOrbit': {
        result = true;
        orbit = +orbit;
        let satIndex;
        if (instr.indexOf(',') === -1) {
            // One instrument
            instr = + instr;
            satIndex = inputs[instr];
            if(inputs[numInstruments + satIndex] != orbit){
                result = false;
            }
        }
        else {
            // Multiple instruments
            let instruments = instr.split(",");
            for(let j = 0; j < instruments.length; j++){
                let temp = +instruments[j];
                satIndex = inputs[temp];
                if(inputs[numInstruments + satIndex] != orbit){
                    result = false;
                    break;
                }
            }
        }
        break;
    }
    case 'notInOrbit': {
        result = true;
        orbit = +orbit;
        let satIndex;
        if (instr.indexOf(',') === -1) {
            // One instrument
            instr = + instr;
            satIndex = inputs[instr];
            if(inputs[numInstruments + satIndex] === orbit){
                result = false;
            }
        }
        else {
            // Multiple instruments
            let instruments = instr.split(",");
            for(let j = 0; j < instruments.length; j++){
                let temp = +instruments[j];
                satIndex = inputs[temp];
                if(inputs[numInstruments + satIndex] === orbit){
                    result = false;
                    break;
                }
            }
        }
        break;
    }
    case 'together': {
        result = true;
        let satIndex = null;
        let instruments = instr.split(',');
        for(let i = 0; i < instruments.length; i++){
            let temp = +instruments[i];
            if(satIndex === null){
                satIndex = inputs[temp];

            }else if(satIndex !== inputs[temp]){
                result = false;
                break;
            }
        }
        break;
    }
    case 'separate': {
        result = true;
        let instruments = instr.split(',');
        let satIndex = null;
        for(let i = 0; i < instruments.length; i++){
            let temp = +instruments[i];
            if(satIndex === null){
                satIndex = inputs[temp];

            }else if(satIndex === inputs[temp]){
                result = false;
                break;

            }
        }
        break;
    }
    case 'emptyOrbit': {
        result = true;
        orbit = +orbit;
        for(let i = 0; i < numInstruments; i++){
            if(inputs[i + numInstruments] === orbit){
                result = false;
                break;
            }
        }
        break;
    }
    case 'numOrbits': {
        let count = 0;
        result = false;
        numb = +numb;
        for(let i = 0; i < numInstruments; i++){
            if(inputs[numInstruments + i] != -1){
                count += 1;
            }
        }
        if(numb === count){
            result = true;
        }
        break;
    }
    case 'numOfInstruments': {
        let count = 0;
        result = false;
        numb = +numb;
        orbit = +orbit;
        let satIndex = null;

        // number of instruments in a specified orbit
        for (let i = 0; i < numInstruments; i++) {
            if(inputs[i + numInstruments] === orbit){
                satIndex = i;
            }
        }

        for(let i = 0; i < numInstruments; i++){
            if(inputs[i] === satIndex){
                count++;
            }
        }

        if(count === numb) {
            result = true;
        }
        break;
    }

    default:
        return false;
    }

    if (flip === true) {
        return !result;
    }
    else {
        return result;
    }
}
/*
    Compares the preset filter to a single architecture
    @param expression: A filter expression string

    @return: A boolean indicating whether the input architecture passes the filter
*/
Compares the preset filter to a single architecture
Compares the preset filter to a single architecture
function applyPresetFilter(inputExpression, data) {
    let expression = removeOuterParentheses(inputExpression);
    expression = expression.substring(1, expression.length-1);
    let flip = false;
    if (expression.startsWith('~')) {
        flip = true;
        expression = expression.substring(1, expression.length);
    }
    let numOrbits = store.state.problem.extra.orbitNum;
    let numInstruments = store.state.problem.extra.instrumentNum;
    let type = expression.split('[')[0];
    let inputs = data.inputs;
    if (type === 'paretoFront') {
        if (data.paretoRanking || data.paretoRanking === 0) {
            let rank = +data.paretoRanking;
            let arg = +expression.substring(0, expression.length-1).split('[')[1];
            return rank <= arg;
        }
    }
    let condition = expression.substring(0, expression.length-1).split('[')[1];
    let condSplit = condition.split(';');
    let orbit, instr, numb;
    orbit = condSplit[0];
    instr = condSplit[1];
    numb = condSplit[2];
    let result;
    switch (type) {
    case 'inOrbit': {
        result = true;
        orbit = +orbit;
        let satIndex;
        if (instr.indexOf(',') === -1) {
            instr = + instr;
            satIndex = inputs[instr];
            if(inputs[numInstruments + satIndex] != orbit){
                result = false;
            }
        }
        else {
            let instruments = instr.split(",");
            for(let j = 0; j < instruments.length; j++){
                let temp = +instruments[j];
                satIndex = inputs[temp];
                if(inputs[numInstruments + satIndex] != orbit){
                    result = false;
                    break;
                }
            }
        }
        break;
    }
    case 'notInOrbit': {
        result = true;
        orbit = +orbit;
        let satIndex;
        if (instr.indexOf(',') === -1) {
            instr = + instr;
            satIndex = inputs[instr];
            if(inputs[numInstruments + satIndex] === orbit){
                result = false;
            }
        }
        else {
            let instruments = instr.split(",");
            for(let j = 0; j < instruments.length; j++){
                let temp = +instruments[j];
                satIndex = inputs[temp];
                if(inputs[numInstruments + satIndex] === orbit){
                    result = false;
                    break;
                }
            }
        }
        break;
    }
    case 'together': {
        result = true;
        let satIndex = null;
        let instruments = instr.split(',');
        for(let i = 0; i < instruments.length; i++){
            let temp = +instruments[i];
            if(satIndex === null){
                satIndex = inputs[temp];
            }else if(satIndex !== inputs[temp]){
                result = false;
                break;
            }
        }
        break;
    }
    case 'separate': {
        result = true;
        let instruments = instr.split(',');
        let satIndex = null;
        for(let i = 0; i < instruments.length; i++){
            let temp = +instruments[i];
            if(satIndex === null){
                satIndex = inputs[temp];
            }else if(satIndex === inputs[temp]){
                result = false;
                break;
            }
        }
        break;
    }
    case 'emptyOrbit': {
        result = true;
        orbit = +orbit;
        for(let i = 0; i < numInstruments; i++){
            if(inputs[i + numInstruments] === orbit){
                result = false;
                break;
            }
        }
        break;
    }
    case 'numOrbits': {
        let count = 0;
        result = false;
        numb = +numb;
        for(let i = 0; i < numInstruments; i++){
            if(inputs[numInstruments + i] != -1){
                count += 1;
            }
        }
        if(numb === count){
            result = true;
        }
        break;
    }
    case 'numOfInstruments': {
        let count = 0;
        result = false;
        numb = +numb;
        orbit = +orbit;
        let satIndex = null;
        for (let i = 0; i < numInstruments; i++) {
            if(inputs[i + numInstruments] === orbit){
                satIndex = i;
            }
        }
        for(let i = 0; i < numInstruments; i++){
            if(inputs[i] === satIndex){
                count++;
            }
        }
        if(count === numb) {
            result = true;
        }
        break;
    }
    default:
        return false;
    }
    if (flip === true) {
        return !result;
    }
    else {
        return result;
    }
}
function applyPresetFilter ( inputExpression , data ) { let expression = removeOuterParentheses ( inputExpression ) ; expression = expression . substring ( 1 , expression . length - 1 ) ; let flip = false ; if ( expression . startsWith ( '~' ) ) { flip = true ; expression = expression . substring ( 1 , expression . length ) ; } let numOrbits = store . state . problem . extra . orbitNum ; let numInstruments = store . state . problem . extra . instrumentNum ; let type = expression . split ( '[' ) [ 0 ] ; let inputs = data . inputs ; if ( type === 'paretoFront' ) { if ( data . paretoRanking || data . paretoRanking === 0 ) { let rank = + data . paretoRanking ; let arg = + expression . substring ( 0 , expression . length - 1 ) . split ( '[' ) [ 1 ] ; return rank <= arg ; } } let condition = expression . substring ( 0 , expression . length - 1 ) . split ( '[' ) [ 1 ] ; let condSplit = condition . split ( ';' ) ; let orbit , instr , numb ; orbit = condSplit [ 0 ] ; instr = condSplit [ 1 ] ; numb = condSplit [ 2 ] ; let result ; switch ( type ) { case 'inOrbit' : { result = true ; orbit = + orbit ; let satIndex ; if ( instr . indexOf ( ',' ) === - 1 ) { instr = + instr ; satIndex = inputs [ instr ] ; if ( inputs [ numInstruments + satIndex ] != orbit ) { result = false ; } } else { let instruments = instr . split ( "," ) ; for ( let j = 0 ; j < instruments . length ; j ++ ) { let temp = + instruments [ j ] ; satIndex = inputs [ temp ] ; if ( inputs [ numInstruments + satIndex ] != orbit ) { result = false ; break ; } } } break ; } case 'notInOrbit' : { result = true ; orbit = + orbit ; let satIndex ; if ( instr . indexOf ( ',' ) === - 1 ) { instr = + instr ; satIndex = inputs [ instr ] ; if ( inputs [ numInstruments + satIndex ] === orbit ) { result = false ; } } else { let instruments = instr . split ( "," ) ; for ( let j = 0 ; j < instruments . length ; j ++ ) { let temp = + instruments [ j ] ; satIndex = inputs [ temp ] ; if ( inputs [ numInstruments + satIndex ] === orbit ) { result = false ; break ; } } } break ; } case 'together' : { result = true ; let satIndex = null ; let instruments = instr . split ( ',' ) ; for ( let i = 0 ; i < instruments . length ; i ++ ) { let temp = + instruments [ i ] ; if ( satIndex === null ) { satIndex = inputs [ temp ] ; } else if ( satIndex !== inputs [ temp ] ) { result = false ; break ; } } break ; } case 'separate' : { result = true ; let instruments = instr . split ( ',' ) ; let satIndex = null ; for ( let i = 0 ; i < instruments . length ; i ++ ) { let temp = + instruments [ i ] ; if ( satIndex === null ) { satIndex = inputs [ temp ] ; } else if ( satIndex === inputs [ temp ] ) { result = false ; break ; } } break ; } case 'emptyOrbit' : { result = true ; orbit = + orbit ; for ( let i = 0 ; i < numInstruments ; i ++ ) { if ( inputs [ i + numInstruments ] === orbit ) { result = false ; break ; } } break ; } case 'numOrbits' : { let count = 0 ; result = false ; numb = + numb ; for ( let i = 0 ; i < numInstruments ; i ++ ) { if ( inputs [ numInstruments + i ] != - 1 ) { count += 1 ; } } if ( numb === count ) { result = true ; } break ; } case 'numOfInstruments' : { let count = 0 ; result = false ; numb = + numb ; orbit = + orbit ; let satIndex = null ; for ( let i = 0 ; i < numInstruments ; i ++ ) { if ( inputs [ i + numInstruments ] === orbit ) { satIndex = i ; } } for ( let i = 0 ; i < numInstruments ; i ++ ) { if ( inputs [ i ] === satIndex ) { count ++ ; } } if ( count === numb ) { result = true ; } break ; } default : return false ; } if ( flip === true ) { return ! result ; } else { return result ; } }
Compares the preset filter to a single architecture
Compares the preset filter to a single architecture
// Preset filter: {presetName[orbits;instruments;numbers]} // One instrument // Multiple instruments // One instrument // Multiple instruments // number of instruments in a specified orbit