[Solved] c# logic approach to dispatch efficiency [closed]


If you are allowed to use external libraries (I assume some homework assignment) you should use the Combinatorics library (via NuGet). If not, do the combinatoric stuff yourself 😉

The idea:
You need all possible (non repeating) combinations of cars and zones to find the combination(s) that gets the most jobs done. Using Variations from the above lib, you already gives you this kind of two-dimensional assigment, because you get a value that has an index.
Please be aware that I’m not a C# guy, but prefer VB …

private string[] jobs = { "Zone 2", "Zone 4", "Zone 45" };
    private string[] cars = {"Frank", "John", "Mary"};

    private void CheckJobs(){

        var k = new Combinatorics.Collections.Variations<string>(jobs.ToList(),3);
        foreach (var c in k)
        {
            int count = 0;
            for (int i = 0; i < 3; i++)
            {
                if(IsPossible(cars[i],c[i])) count++;
                Console.Write("Driver {0} takes {1}   ", cars[i], c[i]);
            }
            Console.WriteLine("Jobs done = {0}", count);
        }
    }

    private Boolean IsPossible(string car, string job)
    {
        if (car == "Mary") {
            return (job == "Zone 2");
        }
        return true;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        CheckJobs();
    }

You can either use all combinations of cars OR jobs. This might be helpfull in cases where you have either more cars or jobs. If for example you have more cars than jobs, you create all variations of cars with a length equal to the number of jobs.
The only thing have to do else, is to simply select the Variations that have the highest number of jobs done (or whatever function you might want to use to measure “efficiency”.

solved c# logic approach to dispatch efficiency [closed]