Last change
on this file since 588 was
583,
checked in by abeham, 16 years ago
|
Adding communication framework to branch 3.1 (ticket #278)
|
File size:
1.1 KB
|
Rev | Line | |
---|
[583] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Data;
|
---|
| 7 |
|
---|
| 8 | namespace HeuristicLab.SimOpt {
|
---|
| 9 | public class Swap2PermutationManipulator : SimOptManipulationOperatorBase {
|
---|
| 10 | public override string Description {
|
---|
| 11 | get { return @"Swap two elements of a permutation or IntArray"; }
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | public Swap2PermutationManipulator()
|
---|
| 15 | : base() {
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | protected override void Apply(IScope scope, IRandom random, IItem item) {
|
---|
| 19 | if (item is Permutation.Permutation || item is IntArrayData) {
|
---|
| 20 | IntArrayData data = (item as IntArrayData);
|
---|
| 21 | int x = random.Next(data.Data.Length);
|
---|
| 22 | int y;
|
---|
| 23 | do {
|
---|
| 24 | y = random.Next(data.Data.Length);
|
---|
| 25 | } while (x == y);
|
---|
| 26 |
|
---|
| 27 | int h = data.Data[x];
|
---|
| 28 | data.Data[x] = data.Data[y];
|
---|
| 29 | data.Data[y] = h;
|
---|
| 30 | } else throw new InvalidOperationException("ERROR: Swap2PermutationManipulator does not know how to work with " + ((item != null) ? (item.GetType().ToString()) : ("null")) + " data");
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.