sum23TestFitnessFunction.sh 1.44 KB
Newer Older
1
#!/usr/bin/fish
2
3


4
if set -q argv[1]
5
6
    # argument defined - we assume command parameter input
    
7
8
9
10
11
12
13
14
15
    echo Candidate vector to evaluate: $argv[1],$argv[2],$argv[3],$argv[4]
    echo ParentsMetadata: $argv[5]
    echo TopNParentsGenerationMetadata: $argv[6]
    
    set summandA $argv[1]
    set summandB $argv[2]
    set summandC $argv[3]
    set summandD $argv[4]
else
16
  	# no argument defined - we assume json input from stdIn
17
18
19
20
21
22
23
    
  	set stdInput (cat)

    set summandA (echo $stdInput | jq -r '.candidateVector[0]')
    set summandB (echo $stdInput | jq -r '.candidateVector[1]')
    set summandC (echo $stdInput | jq -r '.candidateVector[2]')
    set summandD (echo $stdInput | jq -r '.candidateVector[3]')
24

25
26
27
28
29
    echo Candidate vector to evaluate: $summandA,$summandB,$summandC,$summandD
    echo VectorParamNames: (echo $stdInput | jq '.candidateVectorParamNames')
    echo ParentsMetadata: (echo $stdInput | jq '.parentsMetadata')
    echo TopNParentsGenerationMetadata: (echo $stdInput | jq '.eliteMetadata')
end
30
31
32



33
34
# some arbitrary metadata
set metadata '{"shellVarNameExample":"shellVarValueExample","givenVector":"'$summandA','$summandB','$summandC','$summandD'"}'
35
36

# we check if the sum is 23
37
set sum (math $summandA + $summandB + $summandC + $summandD)
38

39
if test $sum -eq 23
40
  # the sum is 23 - we have a match
41
  echo '{"fitness":1.0,"metadata":'"$metadata"'}'
42
else
43
  # the sum is not 23 - we give zero points
44
  echo '{"fitness":0,"metadata":'"$metadata"'}'
45
end