Skip to content

Instantly share code, notes, and snippets.

View jenetics's full-sized avatar
🙄

Franz Wilhelmstötter jenetics

🙄
View GitHub Profile
@jenetics
jenetics / ConstrainedSampleGA.java
Created January 10, 2020 17:03
Structure of a more complex GA problem
import static java.util.Collections.emptyList;
import static io.jenetics.engine.EvolutionResult.toBestPhenotype;
import java.util.List;
import java.util.function.Function;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;
import io.jenetics.DoubleChromosome;
import io.jenetics.DoubleGene;
@jenetics
jenetics / CodecMapping.java
Last active January 13, 2020 20:19
Codec for creating a split double range
/*
* This codec creates a split range, where only values between [0, 2) and
* [8, 10) are valid. The valid range is marked with '-' and the invalid
* range with 'x'.
*
* +--+--+--+--+--+--+--+--+--+--+
* | | | | | | | | | | |
* 0 1 2 3 4 5 6 7 8 9 10
* |-----|xxxxxxxxxxxxxxxxx|-----|
* ^ |llllllll|rrrrrrrr| ^
import io.jenetics.DoubleGene;
import io.jenetics.EnumGene;
import io.jenetics.Genotype;
import io.jenetics.engine.Codec;
import io.jenetics.engine.Codecs;
import io.jenetics.engine.Engine;
import io.jenetics.engine.EvolutionResult;
import io.jenetics.util.DoubleRange;
import io.jenetics.util.ProxySorter;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
@jenetics
jenetics / Lifecycle.java
Created March 9, 2023 20:58
Guaranteed closing of several resources (AutoCloseable)
/*
* Copyright (c) 2023 Franz Wilhelmstötter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software