0

I am writing a program in C++ where there are some variables i want to tune using a genetic algorithm, but finding the fitness value for a single chromosome is relatively slow.

Therefore i want to use concurrency when computing the fitness values of all individuals, but the only way to do this is by using several compiled programs and i want to be able to specify the variables at runtime through the command line (commands are given from a kind of "master" program with a UCI-like protocol), but i dont know any ways to check if there exists a variable with the same name as an input string from cmd.

My question is therefore: Is it even possible to check if a command line input matches a variable name in c++?

BimmerBass
  • 33
  • 4
  • 4
    Once compiled the variable names from the code no longer exist. – drescherjm Jan 01 '21 at 18:07
  • 2
    It is possible if you write the code to do it. Although from a more practical viewpoint, this would basically be normal command line processing -- check if the input matches a given string and do something with it. As an example/explanation: `if ( input_name == "factor" ) factor = input_value;` -- note that in this example, there is no intrinsic reason the string and variable name have to be the same, other than that is what you requested. – JaMiT Jan 01 '21 at 18:15
  • If you have, say, a variable named "grommit", can you explain what difficulty you have with implementing code that simply checks if the word that was read was "grommit"? – Sam Varshavchik Jan 01 '21 at 18:15
  • @JaMiT's solution works if you just have a few such variables. But if you have many, then you might be better off storing the values in a _hash table_ instead of storing the values in variables. – Solomon Slow Jan 01 '21 at 18:21
  • There are command line parsing libraries that can help you with this. One such is: [https://github.com/CLIUtils/CLI11](https://github.com/CLIUtils/CLI11) – drescherjm Jan 01 '21 at 18:26

0 Answers0