A Java library implementing Genetic Algorithms, Fuzzy Logic, and Neural Networks with practical case studies.
Modular implementations of three core soft computing techniques with real-world applications:
- 🧬 Genetic Algorithms: Complete framework with multiple selection, crossover, mutation strategies
- 🧠 Fuzzy Logic: Mamdani/Sugeno inference with customizable rules and membership functions
- 🤖 Neural Networks: Feedforward networks with backpropagation and multiple optimizers
# Compile
javac -d bin src/**/*.java
# Run
java -cp bin MainSelect from three demo applications:
- Job Scheduling - GA optimization
- Restaurant Tipping - Fuzzy logic system
- Facility Classification - Neural network
GeneticAlgorithm<Integer> ga = new GeneticAlgorithm<>();
ga.setPopulationSize(50);
ga.setGenerations(100);
ga.setCrossoverRate(0.7);
ga.setMutationRate(0.01);
ga.setChromosome(new IntChromosome(10, 0, 100));
ga.setFitnessFunction(chromosome -> /* fitness logic */);
ga.setSelectionStrategy(new TournamentSelection<>(3));
ga.setCrossoverStrategy(new UniformCrossover<>());
ga.setMutationStrategy(new SwapMutation<>());
ga.run();Available Strategies:
- Selection: Tournament, Roulette Wheel, Rank
- Crossover: Single-point, N-point, Uniform
- Mutation: Swap, BitFlip, Scramble
- Replacement: Elitist, Generational, Steady-state
// Define variables and fuzzy sets
LinguisticVariable service = new LinguisticVariable("service", 0, 10);
service.addFuzzySet(new FuzzySet("poor", new Triangular(0, 0, 5)));
service.addFuzzySet(new FuzzySet("excellent", new Triangular(5, 10, 10)));
LinguisticVariable tip = new LinguisticVariable("tip", 0, 25);
tip.addFuzzySet(new FuzzySet("low", new Triangular(0, 0, 13)));
tip.addFuzzySet(new FuzzySet("high", new Triangular(13, 25, 25)));
// Create rules
RuleBase ruleBase = new RuleBase();
ruleBase.addRule(new FuzzyRule(
List.of(new FuzzyRule.Condition("service", "poor")), "tip", "low"));
// Evaluate
FuzzyLogicSystem fls = new FuzzyLogicSystem(List.of(service), tip, ruleBase);
double result = fls.evaluate(Map.of("service", 7.5));Features: Triangular/Trapezoidal membership, Mamdani/Sugeno inference, Centroid defuzzification
Hyperparameters params = new Hyperparameters.Builder()
.layerSizes(new int[]{4, 10, 3})
.activationFunction(new ReLU())
.lossFunction(new CrossEntropy())
.optimizer(new Adam(0.001))
.epochs(100)
.batchSize(32)
.build();
NeuralNetwork nn = new NeuralNetwork(params);
nn.train(trainingData, labels);
double[] prediction = nn.predict(input);Components: Sigmoid/ReLU/Tanh activation, MSE/Cross-entropy loss, SGD/Adam/RMSprop optimizers
src/
├── Main.java # Entry point
├── CaseStudies/
│ ├── JobScheduling/ # GA: Job scheduling
│ ├── RestaurantTipping/ # FL: Tipping system
│ └── FacilityClassification/ # NN: Classification
└── SoftComputingTechniques/
├── ga/ # Genetic algorithms
├── fl/ # Fuzzy logic
└── nn/ # Neural networks
| Module | Core Classes |
|---|---|
| GA | GeneticAlgorithm, Chromosome, FitnessFunction, Selection, CrossOver, Mutation |
| FL | FuzzyLogicSystem, LinguisticVariable, FuzzySet, RuleBase, InferenceEngine |
| NN | NeuralNetwork, Layer, Hyperparameters, ActivationFunction, Optimizer |
Job Scheduling (GA) - Optimize job scheduling on machines with time constraints
Restaurant Tipping (FL) - Calculate tips based on service/food quality
Facility Classification (NN) - Classify facilities by accessibility features