Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChomosomeBase vs FloatingPointChromosome #123

Open
nk-alex opened this issue Apr 2, 2024 · 0 comments
Open

ChomosomeBase vs FloatingPointChromosome #123

nk-alex opened this issue Apr 2, 2024 · 0 comments

Comments

@nk-alex
Copy link

nk-alex commented Apr 2, 2024

I'm trying to understand which type of Chromosome should I be considering to solve my problem.

In my case, I receive a ingredient stock. Every ingredient has a price and list of nutrients related. I must generate formulas that accomplish nutritional conditions (a list of nutrients within a specified range) with the minimum cost. So, my GA algorithm, not only has to tell me which ingredient choses, but also its amount. I tried with ChromosomeBase:

public class FormulaChromosome : ChromosomeBase
{
    private readonly List<IngredientContract> _ingredientContracts;

    public FormulaChromosome(List<IngredientContract> ingredientContracts) : base(ingredientContracts.Count)
    {
        _ingredientContracts = ingredientContracts;
        CreateGenes();
    }

    public override Gene GenerateGene(int geneIndex)
    {
        return new Gene(RandomizationProvider.Current.GetInt(0, 101));
    }

    public override IChromosome CreateNew()
    {
        return new FormulaChromosome(_ingredientContracts);
    }

    public List<IngredientContract> GetIngredientContracts()
    {
        var ingredientList = new List<IngredientContract>();
        for (int i = 0; i < Length; i++)
        {
            _ingredientContracts[i].PercentageTaken = (int)(GetGene(i).Value);
            ingredientList.Add(_ingredientContracts[i]);
        }

        return ingredientList;
    }
}

GenerateGene returns an integer [0, 100] which I consider to be the percentage taken of that gene (ingredient) from the given stock.

Is my problem codification ok? Should I change to FloatingPointChromosome for this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant