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
coding query for geeks • Page 2
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.
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 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
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
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.
I dont know either. I prefer a more procedural take so will put some thought to it, there must be a way.
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.
@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.
@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.
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.