| 2583 | } |
| 2584 | |
| 2585 | double cTaskLib::Task_Optimize(cTaskContext& ctx) const |
| 2586 | { |
| 2587 | // if the org hasn't output yet enough numbers, just return without completing any tasks |
| 2588 | if (ctx.GetOutputBuffer().GetNumStored() < ctx.GetOutputBuffer().GetCapacity()) return 0; |
| 2589 | |
| 2590 | double quality = 0.0; |
| 2591 | const cArgContainer& args = ctx.GetTaskEntry()->GetArguments(); |
| 2592 | |
| 2593 | // which function are we currently checking? |
| 2594 | const int function = args.GetInt(0); |
| 2595 | |
| 2596 | // get however many variables need, turn them into doubles between 0 and 1 |
| 2597 | Apto::Array<double> vars; |
| 2598 | vars.Resize(args.GetInt(3)); |
| 2599 | |
| 2600 | double Fx = 0.0; |
| 2601 | |
| 2602 | // some of the problems don't need double variables but use the bit string as a bit string |
| 2603 | // string match, Fx=length - num_matched (0 best, length worst) |
| 2604 | if (function == 20) { |
| 2605 | const cString& string_to_match = args.GetString(0); |
| 2606 | int matched=0; |
| 2607 | for (int i=0; i<args.GetInt(2); i++) { |
| 2608 | if ((string_to_match[i] == '0' && ctx.GetOutputBuffer()[i]==0) || |
| 2609 | (string_to_match[i] == '1' && ctx.GetOutputBuffer()[i]==1)) |
| 2610 | matched++; |
| 2611 | } |
| 2612 | Fx=args.GetInt(2) - matched; |
| 2613 | } |
| 2614 | |
| 2615 | // string with all 1's at beginning until pattern 0101, reward for # 1's |
| 2616 | else if (function == 21) { |
| 2617 | int numOnes=0; |
| 2618 | int patFound=0; |
| 2619 | for (int i=0; i<args.GetInt(2)-3; i++) { |
| 2620 | if (ctx.GetOutputBuffer()[i]==1) numOnes++; |
| 2621 | else { |
| 2622 | if (ctx.GetOutputBuffer()[i+1] == 1 && |
| 2623 | ctx.GetOutputBuffer()[i+2]==0 && ctx.GetOutputBuffer()[i+3]==1) { |
| 2624 | patFound=1; |
| 2625 | } |
| 2626 | break; |
| 2627 | } |
| 2628 | } |
| 2629 | if (patFound) Fx=args.GetInt(2)-4-numOnes; |
| 2630 | else Fx=args.GetInt(2); |
| 2631 | } |
| 2632 | |
| 2633 | // simply rewared for number of 1's at beginning of string, maxFx=length of string |
| 2634 | else if (function == 22) { |
| 2635 | int numOnes=0; |
| 2636 | for (int i=0; i<args.GetInt(2); i++) { |
| 2637 | if (ctx.GetOutputBuffer()[i]==1) numOnes++; |
| 2638 | else break; |
| 2639 | } |
| 2640 | Fx=args.GetInt(2)-numOnes; |
| 2641 | } |
| 2642 |
nothing calls this directly
no test coverage detected