Skip to content

Repository files navigation

Soft Computing Library

A Java library implementing Genetic Algorithms, Fuzzy Logic, and Neural Networks with practical case studies.

Java

Overview

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

Quick Start

# Compile
javac -d bin src/**/*.java
# Run
java -cp bin Main

Select from three demo applications:

  1. Job Scheduling - GA optimization
  2. Restaurant Tipping - Fuzzy logic system
  3. Facility Classification - Neural network

Usage Examples

Genetic Algorithm

GeneticAlgorithm<Integer> ga = newGeneticAlgorithm<>();
ga.setPopulationSize(50);
ga.setGenerations(100);
ga.setCrossoverRate(0.7);
ga.setMutationRate(0.01);
ga.setChromosome(newIntChromosome(10, 0, 100));
ga.setFitnessFunction(chromosome -> /* fitness logic */);
ga.setSelectionStrategy(newTournamentSelection<>(3));
ga.setCrossoverStrategy(newUniformCrossover<>());
ga.setMutationStrategy(newSwapMutation<>());
ga.run();

Available Strategies:

  • Selection: Tournament, Roulette Wheel, Rank
  • Crossover: Single-point, N-point, Uniform
  • Mutation: Swap, BitFlip, Scramble
  • Replacement: Elitist, Generational, Steady-state

Fuzzy Logic

// Define variables and fuzzy setsLinguisticVariableservice = newLinguisticVariable("service", 0, 10);
service.addFuzzySet(newFuzzySet("poor", newTriangular(0, 0, 5)));
service.addFuzzySet(newFuzzySet("excellent", newTriangular(5, 10, 10)));
LinguisticVariabletip = newLinguisticVariable("tip", 0, 25);
tip.addFuzzySet(newFuzzySet("low", newTriangular(0, 0, 13)));
tip.addFuzzySet(newFuzzySet("high", newTriangular(13, 25, 25)));
// Create rulesRuleBaseruleBase = newRuleBase();
ruleBase.addRule(newFuzzyRule(
List.of(newFuzzyRule.Condition("service", "poor")), "tip", "low"));
// EvaluateFuzzyLogicSystemfls = newFuzzyLogicSystem(List.of(service), tip, ruleBase);
doubleresult = fls.evaluate(Map.of("service", 7.5));

Features: Triangular/Trapezoidal membership, Mamdani/Sugeno inference, Centroid defuzzification

Neural Network

Hyperparametersparams = newHyperparameters.Builder()
.layerSizes(newint[]{4, 10, 3})
.activationFunction(newReLU())
.lossFunction(newCrossEntropy())
.optimizer(newAdam(0.001))
.epochs(100)
.batchSize(32)
.build();
NeuralNetworknn = newNeuralNetwork(params);
nn.train(trainingData, labels);
double[] prediction = nn.predict(input);

Components: Sigmoid/ReLU/Tanh activation, MSE/Cross-entropy loss, SGD/Adam/RMSprop optimizers

Project Structure

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

Key Components

ModuleCore Classes
GAGeneticAlgorithm, Chromosome, FitnessFunction, Selection, CrossOver, Mutation
FLFuzzyLogicSystem, LinguisticVariable, FuzzySet, RuleBase, InferenceEngine
NNNeuralNetwork, Layer, Hyperparameters, ActivationFunction, Optimizer

Case Studies

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

About

A library for Soft Computing techniques.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages