Click here to Skip to main content
11,927,711 members (47,217 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
How can the xml file and store large quantities of zero, and if it is not a solution it is. I want to save the initial population Genetic Algorithm
Posted 9-Nov-12 5:49am
Edited 9-Nov-12 6:16am
jim lahey24.9K
OriginalGriff 9-Nov-12 10:50am
I'm sure English is not your native language, but it is the default language for this site.
In English, your question makes no sense at all.
Please, either try to find a better translation of your question to English, or find a site in your own native language, as they may be able to help you better than we can!
Use the "Improve question" widget to edit your question and provide better information.
If a person wants to store "large quantities of zero", learning English more will hardly help... :-)
Ritwesh 9-Nov-12 11:49am
Perfectly agreed. I wish I could give you a +5 here :-). Still one might try learning. Hope these links help:
OriginalGriff 9-Nov-12 11:55am
I dunno, I have an infinite capacity of WOM fitted to this PC - it can hold *huge* quantities of zero without any strain. :laugh:
Yes, you can. I'm talking about someone who can see a problem storing it and needs an advice on it... :-)
rasol123 9-Nov-12 12:25pm
Sorry English is not my native language,I have to store large amounts of zero and one, with columns and rows I need to solve

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I'd avoid using XML, something that maintains the link between the XML structure and the information held would look like:

<?xml version="1.0"?>

The xml is much bigger than the information it contains and problem becomes worse if you are storing bits/bools rather than ints.
Pesonally, as chromosome information is so basic, you could write directly to disk in csv format.

As the CSV format is so simple, I'd do something like this:

public class Chromosome
  char delimiter = ',';
  public List<int> Genes 
     private set;
  public override ToString()
    StringBuilder sb = new StringBuilder();
    foreach(int gene in Genes)
    return sb.ToString().Trim(delimiter);
  public void ReadString(string csv)
    var items = string.split(delimiter);
    foreach (string item in items)
       Genes.Add(int.Parse(item)); //Note this can throw if non-int passed.
I've not tested the above, but you should get the idea. Then all you need do is write to file if required. Google c# streamreader and c# streamwriter for more info.
One thing about my code is that it leaves the serialization in the class, this is not an ideal solution, so you should separate it out. The other thing you could consider is a Custom Serializer[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100