Class NetworkOptimizer

java.lang.Object
neqsim.process.equipment.network.NetworkOptimizer

public class NetworkOptimizer extends Object
Formal NLP and multi-objective optimizer for pipeline network production allocation.

Replaces the gradient-finite-difference approach in LoopedPipeNetwork with mathematically rigorous optimization using Apache Commons Math:

  • BOBYQA: Bound Optimization BY Quadratic Approximation — derivative-free trust-region method. Best for smooth objectives with 2–20 decision variables.
  • CMA-ES: Covariance Matrix Adaptation Evolution Strategy — global optimizer for non-convex, noisy, or multi-modal landscapes. Robust for 5–50 variables.
  • Multi-objective: Weighted-sum scalarization with Pareto front exploration via systematic weight sweep.
Version:
1.0
Author:
Even Solbraa
See Also:
  • Field Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
    • network

      private final LoopedPipeNetwork network
      The network being optimized.
    • algorithm

      private NetworkOptimizer.Algorithm algorithm
      Algorithm selection.
    • maxEvaluations

      private int maxEvaluations
      Maximum function evaluations.
    • objectiveType

      private NetworkOptimizer.ObjectiveType objectiveType
      Objective type.
    • constraintPenalty

      private double constraintPenalty
      Penalty factor for constraint violations.
    • chokeNames

      private List<String> chokeNames
      Choke elements to optimize (names).
    • lowerBounds

      private double[] lowerBounds
      Lower bounds for choke openings (%).
    • upperBounds

      private double[] upperBounds
      Upper bounds for choke openings (%).
    • paretoPoints

      private int paretoPoints
      Number of Pareto front points for multi-objective.
    • lastResult

      Last optimization result.
  • Constructor Details

    • NetworkOptimizer

      public NetworkOptimizer(LoopedPipeNetwork network)
      Create a new network optimizer.
      Parameters:
      network - the pipeline network to optimize
  • Method Details

    • setAlgorithm

      public void setAlgorithm(NetworkOptimizer.Algorithm algorithm)
      Set the optimization algorithm.
      Parameters:
      algorithm - BOBYQA or CMAES
    • getAlgorithm

      public NetworkOptimizer.Algorithm getAlgorithm()
      Get the optimization algorithm.
      Returns:
      algorithm
    • setMaxEvaluations

      public void setMaxEvaluations(int maxEval)
      Set the maximum number of function evaluations.
      Parameters:
      maxEval - maximum evaluations
    • getMaxEvaluations

      public int getMaxEvaluations()
      Get the maximum number of function evaluations.
      Returns:
      maximum evaluations
    • setObjectiveType

      public void setObjectiveType(NetworkOptimizer.ObjectiveType type)
      Set the objective type.
      Parameters:
      type - objective type
    • getObjectiveType

      public NetworkOptimizer.ObjectiveType getObjectiveType()
      Get the objective type.
      Returns:
      objective type
    • setConstraintPenalty

      public void setConstraintPenalty(double penalty)
      Set the constraint penalty factor.
      Parameters:
      penalty - penalty multiplier for each constraint violation
    • getConstraintPenalty

      public double getConstraintPenalty()
      Get the constraint penalty factor.
      Returns:
      penalty
    • setParetoPoints

      public void setParetoPoints(int points)
      Set the number of Pareto front points for multi-objective optimization.
      Parameters:
      points - number of weight combinations to evaluate (minimum 3)
    • getParetoPoints

      public int getParetoPoints()
      Get the number of Pareto front points.
      Returns:
      number of points
    • getLastResult

      public NetworkOptimizer.OptimizationResult getLastResult()
      Get the result from the last optimization run.
      Returns:
      optimization result, or null if not yet run
    • optimize

      Run single-objective optimization of choke openings.

      Discovers all choke elements, constructs bounds, and runs the selected algorithm (BOBYQA or CMA-ES) to optimize the specified objective.

      Returns:
      optimization result with optimal choke openings, objective value, and diagnostics
    • optimizeMultiObjective

      public List<NetworkOptimizer.OptimizationResult> optimizeMultiObjective()
      Run multi-objective optimization: production vs compressor power.

      Explores the Pareto front by sweeping a weight parameter w from 0 to 1:

      f(x) = w * production(x) - (1 - w) * power(x)
      

      Returns a list of Pareto-optimal solutions, each with its production, power, and choke settings.

      Returns:
      list of Pareto-optimal results ordered by increasing production weight
    • runBOBYQA

      private org.apache.commons.math3.optim.PointValuePair runBOBYQA(double[] x0)
      Run BOBYQA (Bound Optimization BY Quadratic Approximation).
      Parameters:
      x0 - initial point (choke openings in %)
      Returns:
      optimal point-value pair
    • runCMAES

      private org.apache.commons.math3.optim.PointValuePair runCMAES(double[] x0)
      Run CMA-ES (Covariance Matrix Adaptation Evolution Strategy).
      Parameters:
      x0 - initial point (choke openings in %)
      Returns:
      optimal point-value pair
    • evaluateObjective

      private double evaluateObjective()
      Evaluate the objective function based on the selected objective type.
      Returns:
      objective value (higher is better)
    • computePenalty

      private double computePenalty()
      Compute constraint violation penalty.
      Returns:
      penalty value (non-negative)
    • getTotalCompressorPower

      private double getTotalCompressorPower()
      Get total compressor power across all compressor elements in the network.
      Returns:
      total power in kW
    • discoverChokeElements

      private void discoverChokeElements()
      Discover choke elements and set up bounds.
    • applyChokeOpenings

      private void applyChokeOpenings(double[] openings)
      Apply choke opening values to the network elements.
      Parameters:
      openings - array of choke openings in % (same order as chokeNames)
    • setChokeBounds

      public void setChokeBounds(String chokeName, double minOpening, double maxOpening)
      Set custom bounds for a specific choke element.
      Parameters:
      chokeName - name of the choke element
      minOpening - minimum opening in % (default 1)
      maxOpening - maximum opening in % (default 100)