coding query for geeks Page 2

    Next Last
  • Nazo 8 Sep 2019 22:32:52 1,039 posts
    Seen 2 hours ago
    Registered 10 years ago
    Interesting problem, it looks like it should be solvable without the random approach. Are there any gotchas? Like, are there always the exact number of optoms and locations or will there be occasions where they don't match up?

    Edit: in fact looking at it some more, some things seem to contradict each other, e.g. it says optom 3 must work at location 4 on Monday am & pm but location 4 is closed all day Monday. How is this resolved?

    Edited by Nazo at 22:54:26 08-09-2019
  • jrmat 9 Sep 2019 09:48:32 108 posts
    Seen 38 minutes ago
    Registered 2 years ago
    Eeep, will double check the files when I get home.

    No gotchas. I'm sure there's a better way without the random approach, I couldn't think of it. Yes, they should always match, I was going to do a pre check to make sure those basics are covered in excel before running the code.

    Will get back about the above query tonight.
  • Nazo 10 Sep 2019 08:32:40 1,039 posts
    Seen 2 hours ago
    Registered 10 years ago
    Some thoughts after looking at it a bit more, don't know how much help it will be.
    You are attempting to solve the problem in the manner that it has been presented, i.e. as a spreadsheet manipulation task, where really it's a business logic task. This makes it hard to reason about what the code is doing and evaluate its approach or correctness. It's very difficult to reconcile lines such as optomfitness
  • grey_matters 10 Sep 2019 09:50:21 4,779 posts
    Seen 54 minutes ago
    Registered 13 years ago
    It won't help with any code tidying but have you tried using more cores? R is single threaded by default and you can gain some time back by splitting the load. I think there's a big overhead but you gain it back well on long runs.

    doParallel library description

    Edited by grey_matters at 09:50:51 10-09-2019
  • jrmat 10 Sep 2019 09:56:14 108 posts
    Seen 38 minutes ago
    Registered 2 years ago
    Apologies I didn't get chance to look at it for long enough last night. I think my example in optom practises is the wrong way around.

    I agree, I don't think I'm solving it the right way, but I can't think up a better way to solve it.

    The code is looking at which practises are closed, which practises an option has to work at for a particular shift, checks the optom is working that shift and then randomly assigns them a practise amongst the remaining practises that aren't closed or already taken. Then at the end the fitness test looks at which practises are the most preferable for each optom. Rinse and repeat.

    I'm very open to a better way or doing it. Very open :-)
  • Nazo 11 Sep 2019 22:06:02 1,039 posts
    Seen 2 hours ago
    Registered 10 years ago
    Yeah, that sounds like the right way to go about it, but i think working directly with spreadsheet-esque data structures will be tricky. I don't know what facilities R provides to organize things differently though.

    Incidentally, the number of permutations of n items is n factorial, which for 7 optoms gives 5040, so exhausting all the permutations should be better than a random approach.
  • jrmat 12 Sep 2019 10:23:17 108 posts
    Seen 38 minutes ago
    Registered 2 years ago
    I dont know either. I prefer a more procedural take so will put some thought to it, there must be a way.
  • Nazo 15 Sep 2019 09:24:43 1,039 posts
    Seen 2 hours ago
    Registered 10 years ago
    Did you figure out the issue with the spreadsheets?
    Iím trying to learn the Rust programming language at the moment and this seems an ideal level of complexity for a learning exercise so Iíll give it a go and share any insights I get from it.
  • Nazo 18 Sep 2019 23:24:00 1,039 posts
    Seen 2 hours ago
    Registered 10 years ago
    @jrmat Not sure if you are still following but I got a version running in Rust. I scored every available permutation of available optoms for each open location and chose the lowest score for each time period, similar to the logic you are using. Without any attempt at optimization (and there are loads of nasty looking nested loops) it produces an answer in < 100ms.

    I strongly suspect the slowness you are having is down to R copying the arrays / matrices when passing them to functions instead of passing by reference.
  • jrmat 19 Sep 2019 06:41:37 108 posts
    Seen 38 minutes ago
    Registered 2 years ago
    @Nazo hi mate, yep, am still following the thread, thanks for your interest. Apologies for radio silence I've had a mad busy couple of weeks and haven't been able to work on it at all. I've barely been able to post here.

    Yes, that makes a lot of sense. I'll look into seeing if there's a way to use pointers in R. I had thought of trying to combine C with VBA to achieve this but I'm not sure.
  • Next Last
Log in or register to reply

Sometimes posts may contain links to online retail stores. If you click on one and make a purchase we may receive a small commission. For more information, go here.