Esempio n. 1
0
        protected virtual void PositionExchangeCrossover(
            SchedulingGenome genome1, SchedulingGenome genome2)
        {
            int nCross = (int) (GA.Random.NextGaussian()
                                * (genome1.InstructionNodes.Count / 6)
                                + (genome1.InstructionNodes.Count / 2));

            nCross = Math.Min(nCross, genome1.InstructionNodes.Count);
            nCross = Math.Max(nCross, 0);

            for (int i = 0; i < nCross; i++) {

                int iNodeIndex =
                    GA.Random.Next(genome1.InstructionNodes.Count);

                InstructionNode iNode =
                    (InstructionNode) genome1.InstructionNodes[iNodeIndex];

                int eu = iNode.Instruction.ExecutionUnit;
                int t1 = genome1.GetInstructionInfo(iNode).SchedulingStep;
                int t2 = genome2.GetInstructionInfo(iNode).SchedulingStep;

                genome1.SwapInstructions(t1, t2, eu);
                genome2.SwapInstructions(t1, t2, eu);

                if (iNode.ResultValue is RegisterValueNode) {

                    Register r1 = genome1.GetValueInfo(iNode.ResultValue).Register;
                    Register r2 = genome2.GetValueInfo(iNode.ResultValue).Register;

                    genome1.GetValueInfo(iNode.ResultValue).Register = r2;
                    genome2.GetValueInfo(iNode.ResultValue).Register = r1;

                    ValueNode depVal =
                        (ValueNode) genome1.CyclicDependencies[iNode.ResultValue];

                    if (depVal != null) {

                        Register dr1 = genome1.GetValueInfo(depVal).Register;
                        Register dr2 = genome2.GetValueInfo(depVal).Register;

                        genome1.GetValueInfo(depVal).Register = dr2;
                        genome2.GetValueInfo(depVal).Register = dr1;
                    }
                }
            }
        }
Esempio n. 2
0
        public virtual void ScheduleMutation(SchedulingGenome genome)
        {
            int nMut = (int) (Math.Abs(GA.Random.NextGaussian())
                              * (genome.InstructionNodes.Count - 1) / 3 + 1);

            nMut = Math.Min(nMut, genome.InstructionNodes.Count);

            for (int i = 0; i < nMut; i++) {

                int iNodeIndex =
                    GA.Random.Next(genome.InstructionNodes.Count);

                InstructionNode iNode =
                    (InstructionNode) genome.InstructionNodes[iNodeIndex];

                int exUnit = iNode.Instruction.ExecutionUnit;
                int t1 = genome.GetInstructionInfo(iNode).SchedulingStep;
                int t2 = GA.Random.Next(genome.Schedule.GetLength(0));

                genome.SwapInstructions(t1, t2, exUnit);
            }
        }
Esempio n. 3
0
        public virtual void ScheduleCrossSwap(SchedulingGenome genome)
        {
            int nMut = (int) (Math.Abs(GA.Random.NextGaussian())
                              * (genome.InstructionNodes.Count - 1) / 3 + 1);

            nMut = Math.Min(nMut, genome.InstructionNodes.Count);

            for (int i = 0; i < nMut; i++) {

                int instrIndex1 =
                    GA.Random.Next(genome.InstructionNodes.Count);

                InstructionNode instr1 = (InstructionNode)
                    genome.InstructionNodes[instrIndex1];

                int instrIndex2 =
                    GA.Random.Next(genome.InstructionNodes.Count);

                InstructionNode instr2 = (InstructionNode)
                    genome.InstructionNodes[instrIndex2];

                IList instrDependencies1 =
                    (IList) genome.Dependencies[instr1];

                IList instrDependencies2 =
                    (IList) genome.Dependencies[instr2];

                int t1 = genome.GetInstructionInfo(instr1).SchedulingStep;
                int t2 = genome.GetInstructionInfo(instr2).SchedulingStep;

                if ((instrDependencies1.Contains(instr2) && t1 <= t2) ||
                    (instrDependencies2.Contains(instr1) && t2 <= t1)) {

                    int eu1 = instr1.Instruction.ExecutionUnit;
                    int eu2 = instr2.Instruction.ExecutionUnit;

                    if (eu1 != eu2) {
                        genome.SwapInstructions(t1, t2, eu1);
                        genome.SwapInstructions(t1, t2, eu2);
                    } else {
                        genome.SwapInstructions(t1, t2, eu1);
                    }
                }
            }
        }
Esempio n. 4
0
        public virtual void ScheduleCompaction(SchedulingGenome genome)
        {
            int nMut = (int) (Math.Abs(GA.Random.NextGaussian())
                              * (genome.InstructionNodes.Count - 1) / 3 + 1);

            nMut = Math.Min(nMut, genome.InstructionNodes.Count);

            for (int i = 0; i < nMut; i++) {

                int iNodeIndex =
                    GA.Random.Next(genome.InstructionNodes.Count);

                InstructionNode iNode =
                    (InstructionNode) genome.InstructionNodes[iNodeIndex];

                int t = genome.GetInstructionInfo(iNode).SchedulingStep;

                if (t > 0) {

                    int exUnit = iNode.Instruction.ExecutionUnit;

                    if (genome.Schedule[t - 1, exUnit] == null)
                        genome.SwapInstructions(t, t - 1, exUnit);
                }
            }
        }