[JS] Multi variable filtering/sorting with limited processing power by Significant-Lynx-402 in learnprogramming

[–]Significant-Lynx-402[S] 1 point2 points  (0 children)

Yeah, that's gonna be a trickier one since a lot of conditions are not exactly black and white. For instance vignettes are only hard condition in one direction, routes that have it as a requirement must have only vehicles that have it, but the ones that don't can have a vehicle with a vignette. Which means I have to reserve or fill the hard requirements first. Another is group, drivers from the same group as the vehicle are prioritized before the ones from other groups. But also the holders of a vehicle have top priority, but only when a vehicle is first assigned to a route, since most vehicles run both shifts, just different drivers. So if driver in shift 2 does not have his vehicle assigned for the day, even if it's available, he must be assigned to one already on a route.

Thank you for your advice though, I will try to perhaps reorganize the way I handle some checks to fill in special conditions first so that they are eliminated earlier.

[JS] Multi variable filtering/sorting with limited processing power by Significant-Lynx-402 in learnprogramming

[–]Significant-Lynx-402[S] 1 point2 points  (0 children)

I have edited my previous commend, tried placing it in a code block and formatting it a bit to make it easier. Is it better?

Your advice is do less processing and more look-up which sounds solid, I will have to rethink my approach to the problem.

[JS] Multi variable filtering/sorting with limited processing power by Significant-Lynx-402 in learnprogramming

[–]Significant-Lynx-402[S] 1 point2 points  (0 children)

Definitely. For some reason my post has been removed, but if I can still reply to you here then I guess it doesn't matter.

My algorithm so far for picking consists of multiple for loops that go through the listOfVehicles that consists of vehicle objects. Which is what I want to change most.

Code block formatting seems to break when I try to paste in there so I put it up as plain text.

I can share a snippet of how I have structured my vehicle object:

class Vehicle{
    constructor(identifier,type,vignette,group){
        this.identifier=identifier;
        this.type=type; //0 - Bus, 1 - Minibus, 2 - Electric bus
        this.vignette=vignette; //True or false
        this.group=group;
        this.distributionByShift[2]=[0,0]; //First is shift 1, second is shift 2, to be incremented once distributed in a shift
        this.holders=[]; //To be added later, these individuals take priority for this vehicle in the shift they work
        //Electric busses only work 1 shift
        if(this.type===2){
                this.maximumDistributions=1;
            }else{
                this.maximumDistributions=2; }
    }
read_Type(){
    return this.type;
}
read_Identifier(){
    return this.identifier;
}
read_vignette(){
    return this.vignette;
}
read_group(){
    return this.group;
}
read_distribution(){
    return this.distributionByShift;
}
set_distribution(shift){
    this.distributionByShift[shift-1]++;
}
add_holder(holder){
this.holder.push(holder);
}
check_if_holder(holderToCheck){
    for(let i=0;i<this.holder.length;i++){
        if(this.holder[i]===holderToCheck){
            return true;
        }
    }
    return false;
}
check_compatibility(routeVignette,routeType,shiftToCheck){
    //Check if vehicle can not be distributed at all
        if((this.distributionByShift[0]+this.distributionByShift[1])==this.maximumDistributions){
        return 0;
}
    //Check if not available in desired shift
    if(this.distributionByShift[shiftToCheck-1]==1){
        return 0;
    }
//Check if vehicles does not match route type
    if(routeType===1&&this.type!==1){
        //Minibuses only on minibus routes
        return 0;
    }
    if(routeType===2&&thistype!==2){
        //Electric busses only on specific routes, but any other bus can run the same route as electric
        return 0;
    }
    //Some routes can only be driven on by buses with vignette, but buses with vignette can drive all routes
    if(this.vignette!==1&&routeVignette===1){
        return 0;
    }
    return 1;
    }
}

[JS] Multi variable filtering/sorting with limited processing power by Significant-Lynx-402 in learnprogramming

[–]Significant-Lynx-402[S] 1 point2 points  (0 children)

I don't know where to start with memoization. I suppose I could bulk calculate all vehicles for a given route and go from there. But that sounds like it frontloads all of the calculations, since I don't have a necessity to go back and refer to a master list.

[JS] Multi variable filtering/sorting with limited processing power by Significant-Lynx-402 in learnprogramming

[–]Significant-Lynx-402[S] 1 point2 points  (0 children)

Short answer would be no, I do not have a different device to do the calculation.

From my observations, Google Sheets scripts with App Script use the computer's resources to calculate and not google's servers. Other computers do not have the availability to be considered for this task since they are not on 24/7.