Fitness function using php in genetic algorithm -


I have a problem with GA for selecting the best employee posts I

this case

I have 4 employees selected ( E1 , E2 , E3 , E4 ) and in their 3 population:

  * Random array (population I) = ([0] = E1 => 200, [1] = E2 => 155, [2] = E3 => 130, [3] = E4 => 98) * Random array (population II) = ([0] = E2 => 155, [1] = E3 = & Gt; 130, [2] = E1 => 200, [3] = E4 => 98) * Random array (population III) = ([0] = E4 => 98, [ 1] = E1 = & gt; 200, [2] = E3 => 1 30, [3] = E2 => 155)  

Then, I want to input that digit in this function:

  f = (N * score [0]) + ((n-1) * score [1]) + score [2] + score [3] / n)  

nb: N is the number of selected employees. Example Fitness Function (Manual Calculation):

  Population I: (4 * 200) + ((4-1) * 155) + 130 + 98/4 = 373,25 Population II: (4 * 155) + ((4-1) * 130) + 200 + 98/4 = 3 27 Population III: (4 * 98) + ((4-1) * 200) + 130 + 155/4 = 319,25  

So how do I apply manual calculation using PHP code?

Can anyone help me? I'm trying it for a week, but there is still no luck: (

Although the formula has two obvious problems with your questions, then first go to them:

  1. How are your arrays really structured on earth? Your examples are not very clear - only one in arrays Key and One Price In my example, I interpreted your examples as literal values And I have divided them into numbers in the function. Adjust to suit.
  2. How do you want this formula how many employees are selected? The first and second entries in my implementation After hard work, then it will automatically run by adding "population" for each value after the first two values.
  3. A bonus question / problem: your formula Finally there is a bracket, which, by a glance, appears from left to right on one side of the formula, indicating that the second part of your formula is added and divided by N, which is incorrect because your expected output value Occurs when the whole result is divided by N. Anyway, here's an implantation:

      function doMyCalculation ($ selection) {// Get the number of selected employees $ num_selected = count ($ Selection); // Break the format of your array - what should it be? Array_walk ($ selection, function (and employee $) {list ($ emp, $ val) = explosion ('=>', $ employee); $ employee = (int) $ val;}); // initial $ return = 0; Loops ($ i = 0; $ i & lt; $ num_selected; $ i ++) through all "Employees" for $ // {// For the first two, we go to use N as multiplier If ($ i & lt; 2) // use [n - present] as multiplier (only twice) $ return + = ($ num_selected - $ i) * $ [$ i] selection; Else // Otherwise, simply add $ return + = $ selection [$ i] to it normally; } // N $ returns / $ num_selected divided by a whole lot; Return refund; } Echo do miklan ($ arr1); // 373.25 echo do macululation ($ arr2); // 327 eco-do macululation ($ arr3); // 319.25  

    If you choose less than four or at least four employees, then how should you think about the above points to work? Answer without that knowledge.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -