using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link] {
public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition,
ISingleObjectiveProblemDefinition {
public bool Maximization { get { return false; } }
public override void Initialize() {
// Use [Link] 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: [Link]);
//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: [Link]))
//.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=[Link]("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=[Link]([Link](0.5*l,2) +[Link]((0.5*t+0.5*h),2));
var J=1.414*h*l*(0.08333*[Link](l,2) + [Link]((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*[Link](t,2));
var tx=[Link]([Link](t1,2)+(2*t1*t2*cos_theta)+[Link](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*([Link](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 [Link] 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 = [Link](qualities, (i, q) => new { Individual = i, Quality = q
}).OrderBy(z => [Link]);
//var best = Maximization ? [Link]().Individual :
[Link]().Individual;
//if () {
// [Link](new Result("Best Solution", typeof(RealVector)));
//}
//results["Best Solution"].Value = (IItem)[Link]("r").Clone();
}
public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
// Use [Link] 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 = [Link]();
// For instance, perform a single bit-flip in a binary parameter
//var bIndex = [Link]([Link]("b").Length);
//[Link]("b")[bIndex] = [bIndex];
yield return neighbor;
}
}
// Implement further classes and methods
}
}