Jump to content

Genetic Algorithm

- - - - -

  • Please log in to reply
8 replies to this topic

#1
debroy

debroy

    Newbie

  • Members
  • Pip
  • 6 posts
I want to develop a Program in C# that :
    Find out all possible way to express a number(Suppose 42) with numbers from 1-9(not 0) and operators(+,-,*,/)(Operators can be used only once).
    ex: 42 = 4 * 9 + 8 - 4/2 or 42 = 4*9 + 6 etc.
Can someone post any guide??

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Well, it doesn't have anything to do with Genetic Algorithms. I'd probably use a recursive algorithm.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
debroy

debroy

    Newbie

  • Members
  • Pip
  • 6 posts
That is not important. What I am wanting to know is how to write Genetic Algorithm in C#?

#4
debroy

debroy

    Newbie

  • Members
  • Pip
  • 6 posts
And Again How can I do it with Recursive Algorithm??

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
To write a genetic algorithm, you first need a problem to solve where a genetic algorithm is appropriate. The details will vary somewhat, but you need an evaluation algorithm and a combination algorithm.

For recursive, I would have the algorithm process n-1 remaining items in an array, and the target value, with each of the operations and return a count of how many ways it can combine the new targets. (not sure if that makes sense)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
debroy

debroy

    Newbie

  • Members
  • Pip
  • 6 posts
Could u please explain it more?? And What type of problem should I need to solve with Genetic Algorithm

#7
anotheruser

anotheruser

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Do you realize that this problem has an infinite amount of solution?

for instance:
6 * 7 is a solution
each of the two factors can be split up like this:
(9 - 3) * (3+4)
as often as you want, creating an infinitely growing tree of possible solutions

You might be able to write a program that shows you all possible mathematical building-blocks to extend a given solution if you only allow natural numbers to be used.

You could also limit the degree how much mathematical functions may split, but I can't see how this would be possible otherwise.

#8
debroy

debroy

    Newbie

  • Members
  • Pip
  • 6 posts
Actually I am using Natural Nums 1-9.and Only + - * / these 4 operators can be used only once each. But the nums can repeat.

Ex : 11+ 31 = 42 is not applicable. And 40 + 1+1 = 42 is also Not Applicable;
but 6*6 + 6 = 42 is applicable;

anotheruser said:

Do you realize that this problem has an infinite amount of solution?

for instance:
6 * 7 is a solution
each of the two factors can be split up like this:
(9 - 3) * (3+4) -> This is N/A because after simplification it becomes 27 - 9 + 36 - 12 Here not only used Natural Nums > 9 but also two operator is used more than once.

I think you understand the Rules:
Rule1 = Only Natural Numbers 1-9 (!0) can be used and they can be used more than once
Rule2 = +,-,*,/ these 4 operators can be used and only once each. Brackets is N/A

as often as you want, creating an infinitely growing tree of possible solutions

You might be able to write a program that shows you all possible mathematical building-blocks to extend a given solution if you only allow natural numbers to be used.

You could also limit the degree how much mathematical functions may split, but I can't see how this would be possible otherwise.
So please give me some idea about Genetic Algo

Edited by Alexander, 25 October 2010 - 04:53 PM.
Merged three posts.


#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
If you are only using each operation once, nested for loops would make more sense, with the different orders as different loops. Why do you want genetic algorithms for this?

Note: a genetic algorithm should be selected as a solution when appropriate. It seems like you have a solution strategy in search of a problem, instead of the other way around.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users