|
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
-
Nazo 1,951 posts
Seen 9 hours ago
Registered 12 years ago -
jrmat 283 posts
Seen 1 day ago
Registered 4 years agoEeep, 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 1,951 posts
Seen 9 hours ago
Registered 12 years agoSome 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 5,507 posts
Seen 1 week ago
Registered 15 years agoIt 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 283 posts
Seen 1 day ago
Registered 4 years agoApologies 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 1,951 posts
Seen 9 hours ago
Registered 12 years agoYeah, 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 283 posts
Seen 1 day ago
Registered 4 years agoI dont know either. I prefer a more procedural take so will put some thought to it, there must be a way. -
Nazo 1,951 posts
Seen 9 hours ago
Registered 12 years agoDid 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 1,951 posts
Seen 9 hours ago
Registered 12 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 283 posts
Seen 1 day ago
Registered 4 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. -
gammonbanter 2,282 posts
Seen 8 hours ago
Registered 14 years agoCan anyone recommend a compiler for C++ I just want to write fairly simple code in notepad and then er, compile and execute it.
After I've played around with that, I'm tempted to move on to visual studio for all my c++ needs. I'm using Windows 10, is there a lightweight alternative! For all its sins I love using IDLE for python and hated Eclipse.
Cheers 😊 -
chopsen 21,958 posts
Seen 10 hours ago
Registered 16 years agoJust download visual studio 2019 and chose console applications in c++. -
gammonbanter wrote:
VS is not a bad choice if you're on Windows. Be aware that you don't need to use VS proper - i.e. the IDE/UI - to build; the compiler can be called separately. You can script it if you so desire (e.g. for automated builds)
Can anyone recommend a compiler for C++ I just want to write fairly simple code in notepad and then er, compile and execute it.
After I've played around with that, I'm tempted to move on to visual studio for all my c++ needs. I'm using Windows 10, is there a lightweight alternative! For all its sins I love using IDLE for python and hated Eclipse.
Cheers 😊
The other big one is the GNU C/C++ compiler. It's a bit more fiddly because it involves a bit more detailed, manual configuration to fine tune things to your needs but it is a very, very powerful one that has been around for a very long time (I've used it 20-25 years ago for the first time IIRC) It's cross-platform too, which may or may not be an advantage for you.
If you want an IDE for it you'll have to pick something though. Out of the box it's nothing more than a compiler/linker. Make files or something similar are always another option.
Theoretically VS and GNU C++ can actually be combined, one as the IDE and the other as the compiler/linker. I've never done so myself however. -
@JoeBlade @chopsen thanks! In the end I downloaded Visual Studio Code and it does everything I need!
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.
