Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Distribute Jobs Fairly on Accounts - Distribution Algorithm in C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 603
    Answer it

    I'm working on a project that publish to a multiple websites using a multiple accounts. each account can publish to a specific website. as shown in the 'Dict' below. The problem is I'm trying to distribute the publishing jobs on accounts fairly and making a distance between accounts that has more than 1 job.

    So, Let's say that we have the following accounts list:

     

    _accounts = new List<string>{"Account-A", "Account-B", "Account-C", "Account-D", "Account-E"};
    

    and the following sites list:

    var sites = new List<string>{"Site-A", "Site-B", "Site-C", "Site-D", "Site-E"};

    Each account can publish to a specific site according to the following dynamic dictionary:

    Key: Is the 'site ID' and value is a list of accounts IDs that can publish to that site

    Dict.Add("Site-A", new List<string>{"Account-A", "Account-C"});
    Dict.Add("Site-B", new List<string>{"Account-A", "Account-E"});
    Dict.Add("Site-C", new List<string>{"Account-C", "Account-D"});
    Dict.Add("Site-D", new List<string>{"Account-A"});
    Dict.Add("Site-E", new List<string>{"Account-A"});
    

     

    Publishing jobs are created as follows:

     

    var jobs = new List<Job>();
    foreach (var site in sites)
    {        
        var job = new Job();
    
        // Get a random account from  _accounts that can post to a site
        // Lookup the entries in Dict and determine accounts that can publish to site
        var acct = GetAccountCanPost(Dict, site, _accounts);
    
        job.Site = site;
        job.Account = acct;
    
        jobs.Add(job);
    }
    
    
    public static string GetAccountCanPost(Dictionary<string, List<string>> dict, string targetSite, List<string> accounts)
    {
        var accountIdsAssoc = GetAccountsIdsAssociatedWithSite(dict, targetSite);
    
        var selectedId = accountIdsAssoc.PickRandomAccount();
        var account = accounts.FirstOrDefault(s => s == selectedId);
    
        return account;
    }
    

     

    when the jobs are created it is something similar to (Before re-adjusting the jobs distribution)

    > Account-A Publish on Site-A 
    > Account-E Publish on Site-B
    > Account-D Publish on Site-C
    > Account-A Publish on Site-D
    > Account-A Publish on Site-E
    

    The publishing jobs created above are not fairly distributed to accounts, as you can see 'Account-A' has 3 jobs assigned while there's an other accounts can publish to the 'sites' as defined in 'Dict' so it should look something like:

     

    > Account-C Publish on Site-A
    > Account-E Publish on Site-B
    > Account-A Publish on Site-D
    > Account-D Publish on Site-C
    > Account-A Publish on Site-E
    

     

    In the output above the jobs are distributed fairly on accounts and also there's a distance between accounts that has more than 1 job

    An example on distance between jobs:

        > Account-A Publish on Site-A 
        > Account-E Publish on Site-B
        > Account-D Publish on Site-C
        > Account-A Publish on Site-D
        > Account-A Publish on Site-E
    

    Job 4 and 5 are being processed by Account-A. An account should not process two jobs sequentially, so it could be swapped with another job, something like this

        > Account-A Publish on Site-A 
        > Account-E Publish on Site-B
        > Account-A Publish on Site-D
        > Account-D Publish on Site-C
        > Account-A Publish on Site-E
    

     

    It will be highly appreciated if you could help. I need an algorithm that do the job distribution to get similar output. Performance is not important.

    Thank you..

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: