0% found this document useful (0 votes)
26 views

Programa

This document defines a CompiledSingleObjectiveProblemDefinition class within the HeuristicLab.Problems.Programmable namespace. The class implements the ISingleObjectiveProblemDefinition interface and is used to define a compiled single objective optimization problem. It initializes the solution encoding, evaluates individuals to calculate fitness scores, analyzes results, and generates neighboring solutions.

Uploaded by

jdmu2013
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Programa

This document defines a CompiledSingleObjectiveProblemDefinition class within the HeuristicLab.Problems.Programmable namespace. The class implements the ISingleObjectiveProblemDefinition interface and is used to define a compiled single objective optimization problem. It initializes the solution encoding, evaluates individuals to calculate fitness scores, analyzes results, and generates neighboring solutions.

Uploaded by

jdmu2013
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Linq;
using System.Collections.Generic;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.BinaryVectorEncoding;
using HeuristicLab.Encodings.IntegerVectorEncoding;
using HeuristicLab.Encodings.RealVectorEncoding;
using HeuristicLab.Encodings.PermutationEncoding;
using HeuristicLab.Encodings.LinearLinkageEncoding;
using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
using HeuristicLab.Optimization;
using HeuristicLab.Problems.Programmable;

namespace HeuristicLab.Problems.Programmable {
public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition,
ISingleObjectiveProblemDefinition {
public bool Maximization { get { return false; } }

public override void Initialize() {


// Use vars.yourVariable to access variables in the variable store i.e. yourVariable
// Define the solution encoding which can also consist of multiple vectors, examples below
//Encoding = new BinaryVectorEncoding("b", length: 5);
//Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 2);
Encoding = new RealVectorEncoding("r", length: 4, min: 0.0, max: 10.0);
//Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
//Encoding = new LinearLinkageEncoding("l", length: 5);
//Encoding = new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(),
50, 12);
// The encoding can also be a combination
//Encoding = new MultiEncoding()
//.Add(new BinaryVectorEncoding("b", length: 5))
//.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4))
//.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0))
//.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
//.Add(new LinearLinkageEncoding("l", length: 5))
//.Add(new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50,
12))
;
// Add additional initialization code e.g. private variables that you need for evaluating
}

public double Evaluate(Individual individual, IRandom random) {


//Asignación de los genes del cromosoma
var cromosoma=individual.RealVector("r");
var h=cromosoma[0]; var l=cromosoma[1];var t=cromosoma[2];var b=cromosoma[3];

//Parámetros del problema


var L=12;var F=7200;var td=13600;var sd=30000;

//Definición de funciones
var M=F*(L+0.5*l);
var R=Math.Sqrt(Math.Pow(0.5*l,2) +Math.Pow((0.5*t+0.5*h),2));
var J=1.414*h*l*(0.08333*Math.Pow(l,2) + Math.Pow((0.5*t+0.5*h),2));
var t1=(0.70711*F)/(h*l);
var t2=(M*R)/J;

var cos_theta=l/(2*R);
var sx=(6*F*L)/(b*Math.Pow(t,2));
var tx=Math.Sqrt(Math.Pow(t1,2)+(2*t1*t2*cos_theta)+Math.Pow(t2,2));

//Restricciones
var g1=0;var g2=0;var g3=0;var g4=0;var g5=0;var g6=0;

if(td<=tx) {g1=100000;} else{g1=0;}


if(sd<=sx) {g2=100000;} else{g2=0;}
if(b<=h) {g3=100000;} else{g3=0;}
if(l<=0) {g4=100000;} else{g4=0;}
if(t<=0) {g5=100000;} else{g5=0;}
if(h<=0.125){g6=100000;} else{g6=0;}

//Función de calidad
var costo=(1.13*(Math.Pow(h,2))*l) + (0.08*t*b*(L+l)) + g1 + g2 + g3 + g4 + g5 + g6;
return costo;
}

public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom


random) {
// Use vars.yourVariable to access variables in the variable store i.e. yourVariable
// Write or update results given the range of vectors and resulting qualities
// Uncomment the following lines if you want to retrieve the best individual

//var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q


}).OrderBy(z => z.Quality);
//var best = Maximization ? orderedIndividuals.Last().Individual :
orderedIndividuals.First().Individual;
//if (!results.ContainsKey("Best Solution")) {
// results.Add(new Result("Best Solution", typeof(RealVector)));
//}
//results["Best Solution"].Value = (IItem)best.RealVector("r").Clone();
}

public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {


// Use vars.yourVariable to access variables in the variable store i.e. yourVariable
// Create new vectors, based on the given one that represent small changes
// This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
while (true) {
// Algorithm will draw only a finite amount of samples
// Change to a for-loop to return a concrete amount of neighbors
var neighbor = individual.Copy();
// For instance, perform a single bit-flip in a binary parameter
//var bIndex = random.Next(neighbor.BinaryVector("b").Length);
//neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
yield return neighbor;
}
}

// Implement further classes and methods


}
}

You might also like