colgreen / sharpneat

SharpNEAT - Evolution of Neural Networks. A C# .NET Framework.
https://sharpneat.sourceforge.io/
Other
380 stars 97 forks source link

Parsing default values fails in cultures that are not en-us... #26

Closed CRAceDKR closed 6 years ago

CRAceDKR commented 6 years ago

If the GUI program is run as-is on a pc with different culture it may throw an unhandled exception with an index out of range - this is caused by selecting more genomes than are available, but the root cause is a parsing error.

From SharpNeatGUI.MainForm (and MainForm.Designer):

InitializeComponent()

this.txtParamSelectionProportion.Text = "0.2"; //either en-us or generic


ReadAndUpdateExperimentParams()

eaParams.SelectionProportion = ParseDouble(txtParamSelectionProportion, eaParams.SelectionProportion);


ParseDouble()

if(double.TryParse(txtBox.Text, out val)) // No culture specified... sets SelectionProportion to 2 in countries using 0,2 instead of 0.2

CRAceDKR commented 6 years ago

Can be fixed with (although then locking the parsing to invariant culture):

if(double.TryParse(txtBox.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out val))

CRAceDKR commented 6 years ago

Also - default experiments uses the same culture in the config xml. Problem in XmlUtils.cs:

TryGetValueAsDouble

if(double.TryParse(valStr, out result)) // Needs culture info


Possible fix:

if(double.TryParse(valStr, NumberStyles.Float, CultureInfo.InvariantCulture, out result))

CRAceDKR commented 6 years ago

Same issue (in reverse) with a lot of ToString() - really need to specify invariant culture. Or find another way of reading in default values from config files etc.

colgreen commented 6 years ago

To address this issue I have set the default culture for the entire app to the invariant culture. This not ideal but should be fine for because I don't think the GUI as a whole is culture aware (e.g. menu titles are all fixed in English).

The ideal solution is to have the data IO routines be invariant culture throughout (and not changeable), but for the GUI fields to use the local culture, and not have hard coded textual values like "0.2".

Thanks for reporting.