Class ProductionOptimizationSpecLoader
java.lang.Object
neqsim.process.util.optimizer.ProductionOptimizationSpecLoader
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classConstraint specification in the YAML/JSON file.private static final classObjective specification in the YAML/JSON file.private static final classIndividual scenario configuration from YAML/JSON.private static final classRoot element of the specification file.private static final classVariable specification for multi-variable optimization. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionload(Path specPath, Map<String, ProcessSystem> processes, Map<String, StreamInterface> feeds, Map<String, ToDoubleFunction<ProcessSystem>> metrics) Parse a YAML/JSON specification file into scenario requests.private static ToDoubleFunction<ProcessSystem> requireMetric(Map<String, ToDoubleFunction<ProcessSystem>> metrics, String key) Looks up a metric function by key, throwing if not found.
-
Constructor Details
-
ProductionOptimizationSpecLoader
private ProductionOptimizationSpecLoader()
-
-
Method Details
-
load
public static List<ProductionOptimizer.ScenarioRequest> load(Path specPath, Map<String, ProcessSystem> processes, Map<String, StreamInterface> feeds, Map<String, ToDoubleFunction<ProcessSystem>> metrics) throws IOException Parse a YAML/JSON specification file into scenario requests.This method reads a specification file and converts it into a list of
ProductionOptimizer.ScenarioRequestobjects that can be executed byProductionOptimizer. The file format (YAML or JSON) is auto-detected based on the file extension.- Parameters:
specPath- path to the YAML (.yaml, .yml) or JSON (.json) specification fileprocesses- map of process name (as used in spec) to ProcessSystem instancesfeeds- map of feed stream name (as used in spec) to StreamInterface instancesmetrics- map of metric name (as used in spec) to evaluation functions- Returns:
- list of ScenarioRequest objects ready for optimization
- Throws:
IOException- if the file cannot be read or parsedIllegalArgumentException- if a referenced process, feed, or metric is not found in the provided maps
-
requireMetric
private static ToDoubleFunction<ProcessSystem> requireMetric(Map<String, ToDoubleFunction<ProcessSystem>> metrics, String key) Looks up a metric function by key, throwing if not found.- Parameters:
metrics- the metrics map to searchkey- the metric key to look up- Returns:
- the metric evaluation function
- Throws:
IllegalArgumentException- if the key is not found
-