Class ProductionOptimizationSpecLoader

java.lang.Object
neqsim.process.util.optimizer.ProductionOptimizationSpecLoader

public final class ProductionOptimizationSpecLoader extends Object
Loader for YAML/JSON optimization specification files.

This class parses YAML or JSON specification files that define optimization scenarios for production optimization. It enables configuration-driven optimization where scenarios, variables, objectives, and constraints are defined in external files rather than code.

YAML Format Specification:

scenarios:
  - name: "Scenario1"
    process: "myProcess"           # Key in processes map
    feedStream: "myFeed"           # Key in feeds map (for single-variable)
    lowerBound: 50000.0            # Min flow rate
    upperBound: 200000.0           # Max flow rate
    rateUnit: "kg/hr"              # Unit for bounds
    tolerance: 100.0               # Convergence tolerance
    maxIterations: 30              # Max solver iterations
    searchMode: "GOLDEN_SECTION_SCORE"  # BINARY_FEASIBILITY, GOLDEN_SECTION_SCORE,
                                        # NELDER_MEAD_SCORE, PARTICLE_SWARM_SCORE
    utilizationMarginFraction: 0.05     # 5% margin on equipment limits
    capacityUncertaintyFraction: 0.0    # Uncertainty buffer
    capacityPercentile: 0.5             # P50 capacity
    enableCaching: true                 # Cache evaluations
    columnFsFactorLimit: 2.5            # Distillation column Fs factor limit

    # Multi-variable optimization (instead of feedStream)
    variables:
      - name: "flowRate"
        stream: "feedStream"       # Key in feeds map
        lowerBound: 50000.0
        upperBound: 200000.0
        unit: "kg/hr"
      - name: "pressure"
        stream: "compOutlet"
        lowerBound: 100.0
        upperBound: 150.0
        unit: "bara"

    # Objectives
    objectives:
      - name: "throughput"
        weight: 1.0
        type: "MAXIMIZE"           # MAXIMIZE or MINIMIZE
        metric: "throughputMetric" # Key in metrics map

    # Constraints
    constraints:
      - name: "maxPower"
        metric: "powerMetric"      # Key in metrics map
        limit: 5000.0
        direction: "LESS_THAN"     # LESS_THAN or GREATER_THAN
        severity: "HARD"           # HARD or SOFT
        penaltyWeight: 0.0         # For SOFT constraints
        description: "Compressor power limit"

Java Usage Example:

// 1. Build process and create registries
ProcessSystem process = new ProcessSystem();
// ... add equipment ...
process.run();

StreamInterface feed = (StreamInterface) process.getUnit("feed");

// 2. Create mapping registries
Map<String, ProcessSystem> processes = new HashMap<>();
processes.put("myProcess", process);

Map<String, StreamInterface> feeds = new HashMap<>();
feeds.put("myFeed", feed);

Map<String, ToDoubleFunction<ProcessSystem>> metrics = new HashMap<>();
metrics.put("throughputMetric", p -> p.getUnit("outlet").getFlowRate("kg/hr"));
metrics.put("powerMetric", p -> ((Compressor) p.getUnit("comp")).getPower("kW"));

// 3. Load and run scenarios
Path specFile = Paths.get("optimization_scenarios.yaml");
List<ScenarioRequest> scenarios =
    ProductionOptimizationSpecLoader.load(specFile, processes, feeds, metrics);

ProductionOptimizer optimizer = new ProductionOptimizer();
for (ScenarioRequest scenario : scenarios) {
  OptimizationResult result = optimizer.optimizeScenario(scenario);
  System.out.println(scenario.getName() + ": " + result.getOptimalRate());
}

Python Usage Example (via JPype):

from neqsim.neqsimpython import jneqsim
from jpype import JImplements, JOverride
import java.nio.file.Paths as JPaths
import java.util.HashMap as JHashMap

# Get Java classes
SpecLoader = jneqsim.process.util.optimizer.ProductionOptimizationSpecLoader

# Create registries
processes = JHashMap()
processes.put("myProcess", process)

feeds = JHashMap()
feeds.put("myFeed", process.getUnit("feed"))

# Create metrics with Java interface
@JImplements("java.util.function.ToDoubleFunction")
class ThroughputMetric:
    @JOverride
    def applyAsDouble(self, proc):
        return proc.getUnit("outlet").getFlowRate("kg/hr")

metrics = JHashMap()
metrics.put("throughputMetric", ThroughputMetric())

# Load scenarios
spec_path = JPaths.get("optimization_scenarios.yaml")
scenarios = SpecLoader.load(spec_path, processes, feeds, metrics)

# Run each scenario
optimizer = jneqsim.process.util.optimizer.ProductionOptimizer()
for scenario in scenarios:
    result = optimizer.optimizeScenario(scenario)
    print(f"{scenario.getName()}: {result.getOptimalRate():.0f}")
Version:
1.0
Author:
NeqSim Development Team
See Also: