Ejemplo 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;
                    }
                }
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
                    }
                }
            }
        }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 5
0
        protected virtual int GetViolatedSchedulingConstraints(
            SchedulingGenome genome)
        {
            int violatedConstraints = 0;

            foreach (InstructionNode instr in genome.InstructionNodes) {

                int instrStep = genome.GetInstructionInfo(instr).SchedulingStep;
                IList instrDependencies = (IList) genome.Dependencies[instr];

                foreach (InstructionNode depInstr in instrDependencies) {

                    int depInstrStep =
                        genome.GetInstructionInfo(depInstr).SchedulingStep;

                    if (instrStep <= depInstrStep)
                        violatedConstraints += 1;
                }

                /*
                foreach (ValueNode depVal in instr.OperandValues) {

                    if (!depVal.IsInputValue()) {

                        InstructionNode depInstr =
                            depVal.ProducingInstruction;

                        int instrStep =
                            genome.GetInstructionInfo(instr).SchedulingStep;
                        int depInstrStep =
                            genome.GetInstructionInfo(depInstr).SchedulingStep;

                        if (depInstrStep >= instrStep)
                            violatedConstraints += depInstrStep - instrStep + 1;
                    }
                }
                */
            }

            return violatedConstraints;
        }
Ejemplo n.º 6
0
        protected virtual void RelativeOrderCrossoverForExUnit(
            SchedulingGenome genome1, SchedulingGenome genome2,
            int exUnit, IList instructionsOnExUnit)
        {
            int nCross = (int) (GA.Random.NextGaussian()
                                * (instructionsOnExUnit.Count / 6)
                                + (instructionsOnExUnit.Count / 2));

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

            InstructionNode[] selectedInstr1 = new InstructionNode[nCross];
            InstructionNode[] selectedInstr2 = new InstructionNode[nCross];

            int[] instrSteps1 = new int[nCross];
            int[] instrSteps2 = new int[nCross];

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

                int selectedInstrIndex =
                    GA.Random.Next(instructionsOnExUnit.Count);

                InstructionNode selectedInstr =
                    (InstructionNode) instructionsOnExUnit[selectedInstrIndex];

                selectedInstr1[i] = selectedInstr;
                selectedInstr2[i] = selectedInstr;

                instrSteps1[i] = genome1.GetInstructionInfo(
                    selectedInstr).SchedulingStep;

                instrSteps2[i] = genome2.GetInstructionInfo(
                    selectedInstr).SchedulingStep;
            }

            Array.Sort(instrSteps1, selectedInstr2);
            Array.Sort(instrSteps2, selectedInstr1);

            for (int i = 0; i < nCross; i++) {
                genome1.ScheduleInstructionForStep(
                    selectedInstr1[i], instrSteps1[i]);
                genome2.ScheduleInstructionForStep(
                    selectedInstr2[i], instrSteps2[i]);
            }
        }
Ejemplo n.º 7
0
        public virtual void Copy(
            SchedulingGenome other,
            IDictionary instructionMap,
            IDictionary valueMap)
        {
            population = other.population;
            scheduler = other.scheduler;

            schedule = new InstructionNode[
                other.schedule.GetLength(0),
                other.schedule.GetLength(1)];

            for (int i = 0; i < schedule.GetLength(0); i++) {
                for (int j = 0; j < schedule.GetLength(1); j++) {

                    InstructionNode iNode = other.schedule[i, j];

                    if (iNode != null) {
                        schedule[i, j] =
                            (InstructionNode) instructionMap[other.schedule[i, j]];
                    } else {
                        schedule[i, j] = null;
                    }
                }
            }

            valueInfos = new Hashtable();

            foreach (ValueNode vNode in other.ValueInfos.Keys) {

                ValueInfo info = new ValueInfo();
                ValueInfo otherInfo = other.GetValueInfo(vNode);

                info.Register = otherInfo.Register;
                info.Production = otherInfo.Production;
                info.LastUsage = otherInfo.LastUsage;
                valueInfos[valueMap[vNode]] = info;
            }

            instructionInfos = new Hashtable();

            foreach (InstructionNode iNode in other.InstructionInfos.Keys) {

                InstructionInfo info = new InstructionInfo();
                InstructionInfo otherInfo = other.GetInstructionInfo(iNode);

                info.SchedulingStep = otherInfo.SchedulingStep;
                instructionInfos[instructionMap[iNode]] = info;
            }

            isValid = other.isValid;
            scheduleLength = other.scheduleLength;
            violatedSchedulingConstraints = other.violatedSchedulingConstraints;
            violatedRegisterConstraints = other.violatedRegisterConstraints;
            generationOfBirth = other.generationOfBirth;
        }