Domain-Specific Optimization
Use pre-built libraries for finance, healthcare, supply chain, manufacturing, energy, and ML.
Why Domain Libraries?
Domain libraries provide pre-configured optimization patterns with industry-specific constraints, compliance checks, and domain-aware explanations. Instead of building from scratch, you get:
✓ Built-in Constraints
Industry regulations, safety limits, best practices
✓ Compliance Checks
Basel III, HIPAA, OSHA, NERC, and more
✓ Domain Explanations
Results explained in industry terminology
✓ Faster Development
Production-ready patterns, not prototypes
💼 Financial Services
Portfolio optimization with regulatory compliance, risk measures, and audit trails:
from sematryx.domains import finance
import numpy as np
# Portfolio optimization with regulatory constraints
result = finance.optimize_portfolio(
# Asset data
returns=np.array([0.12, 0.08, 0.15, 0.10, 0.07]),
covariance=cov_matrix,
# Portfolio constraints
constraints={
'max_position': 0.30, # Max 30% in any single asset
'min_position': 0.02, # Min 2% if included
'max_sector': {
'tech': 0.40,
'finance': 0.30,
'healthcare': 0.25
},
'min_return': 0.08, # Minimum target return
'max_turnover': 0.20 # Max 20% portfolio turnover
},
# Risk configuration
risk_measure='cvar', # Conditional Value at Risk
confidence_level=0.95,
# Regulatory compliance
regulatory='basel_iii',
# Explainability for compliance
explanation_level=4
)
# Results include compliance check
print(f"Allocation: {result['allocation']}")
print(f"Expected return: {result['expected_return']:.2%}")
print(f"CVaR (95%): {result['risk_metrics']['cvar']:.2%}")
print(f"Compliance: {result['compliance_check']['status']}")🏥 Healthcare
Resource allocation and scheduling with patient safety constraints:
from sematryx.domains import healthcare
# Hospital resource allocation
result = healthcare.optimize_scheduling(
# Resource definitions
resources={
'nurses': {'count': 50, 'shifts': ['day', 'evening', 'night']},
'doctors': {'count': 20, 'specialties': ['general', 'surgery', 'icu']},
'beds': {'icu': 30, 'general': 150, 'surgical': 40}
},
# Demand forecast
demand_forecast=weekly_demand,
# Healthcare-specific constraints
constraints={
'min_nurse_patient_ratio': 0.25, # At least 1 nurse per 4 patients
'max_consecutive_shifts': 2, # No more than 2 back-to-back shifts
'skill_coverage': True, # Required skills always covered
'break_requirements': 'union_rules' # Comply with labor agreements
},
# Patient safety constraints (hard)
safety_constraints={
'icu_coverage': 'always',
'emergency_buffer': 0.15 # 15% capacity buffer
},
# Optimization objectives
objectives={
'minimize': ['overtime_cost', 'travel_time'],
'maximize': ['staff_satisfaction', 'coverage_quality']
}
)
# Results include safety verification
print(f"Schedule feasible: {result['feasible']}")
print(f"Safety constraints: {result['safety_verified']}")
print(f"Overtime hours: {result['metrics']['overtime_hours']}")🚚 Supply Chain
Inventory optimization across multi-echelon networks with demand uncertainty:
from sematryx.domains import supply_chain
# Multi-echelon inventory optimization
result = supply_chain.optimize_inventory(
# Network structure
network={
'warehouses': warehouse_data,
'distribution_centers': dc_data,
'stores': store_data
},
# Demand and lead times
demand_forecast=demand_by_sku,
lead_times=supplier_lead_times,
# Inventory constraints
constraints={
'service_level': 0.95, # 95% fill rate target
'max_holding_cost': budget,
'min_safety_stock_days': 7,
'max_warehouse_capacity': capacities
},
# Supply chain specific objectives
objectives={
'minimize': ['total_inventory_cost', 'stockout_risk'],
'balance': 'cost_vs_service'
},
# Uncertainty handling
demand_uncertainty='stochastic',
scenarios=1000
)
# Results include multi-echelon policies
print(f"Reorder points: {result['reorder_points']}")
print(f"Safety stock: {result['safety_stock']}")
print(f"Expected cost: ${result['expected_cost']:,.0f}")
print(f"Service level achieved: {result['service_level']:.1%}")🏭 Manufacturing
Production scheduling with quality, safety, and energy constraints:
from sematryx.domains import manufacturing
# Production scheduling with quality constraints
result = manufacturing.optimize_production(
# Product and machine data
products=product_specs,
machines=machine_capabilities,
# Production requirements
demand=weekly_demand,
due_dates=customer_due_dates,
# Manufacturing constraints
constraints={
'setup_times': setup_matrix,
'batch_sizes': min_batch_sizes,
'maintenance_windows': maintenance_schedule,
'quality_requirements': quality_specs
},
# Safety and compliance (HARD constraints)
safety_constraints={
'max_continuous_operation': 8, # Hours before required break
'temperature_limits': temp_ranges,
'hazmat_handling': 'osha_compliant'
},
# Energy optimization
energy_config={
'peak_pricing_hours': peak_hours,
'energy_limit': max_kwh,
'prefer_off_peak': True
},
# Objectives
objectives=['minimize_makespan', 'minimize_energy', 'maximize_quality']
)
# Results include Gantt chart data
print(f"Makespan: {result['makespan_hours']} hours")
print(f"Energy cost: ${result['energy_cost']:,.0f}")
print(f"Quality score: {result['quality_metrics']['cpk']}")⚡ Energy & Utilities
Grid optimization with renewable integration and reliability standards:
from sematryx.domains import energy
# Grid optimization with renewables
result = energy.optimize_grid(
# Generation assets
generators={
'solar': solar_capacity,
'wind': wind_capacity,
'gas': gas_plants,
'storage': battery_storage
},
# Demand and forecasts
demand_forecast=hourly_demand,
solar_forecast=solar_production,
wind_forecast=wind_production,
# Grid constraints
constraints={
'frequency_tolerance': 0.01, # 1% frequency deviation max
'voltage_limits': voltage_bounds,
'transmission_capacity': line_limits,
'spinning_reserve': 0.10 # 10% reserve margin
},
# Regulatory requirements
regulatory={
'renewable_minimum': 0.30, # 30% renewable mandate
'emissions_cap': co2_limit,
'reliability_standard': 'nerc'
},
# Multi-objective
objectives={
'minimize': ['cost', 'emissions', 'curtailment'],
'maximize': ['reliability', 'renewable_utilization']
}
)
# Results include dispatch schedule
print(f"Total cost: ${result['total_cost']:,.0f}")
print(f"Renewable %: {result['renewable_percentage']:.1%}")
print(f"CO2 emissions: {result['emissions_tons']} tons")🔬 Machine Learning
Hyperparameter tuning with cross-validation and learning from similar problems:
from sematryx.domains import ml
# Hyperparameter optimization
result = ml.optimize_hyperparameters(
# Model and data
model_type='xgboost',
train_data=X_train,
train_labels=y_train,
validation_data=X_val,
validation_labels=y_val,
# Hyperparameter search space
search_space={
'learning_rate': (0.001, 0.3, 'log'),
'max_depth': (3, 12, 'int'),
'n_estimators': (50, 500, 'int'),
'subsample': (0.5, 1.0),
'colsample_bytree': (0.5, 1.0)
},
# Optimization config
metric='f1_weighted',
cv_folds=5,
max_evaluations=100,
# Early stopping
early_stopping_rounds=10,
# Use learning from similar problems
use_learning=True,
problem_signature='classification_tabular'
)
# Results include best params and CV scores
print(f"Best params: {result['best_params']}")
print(f"Best CV score: {result['best_cv_score']:.4f}")
print(f"Evaluations: {result['evaluations']}")Custom Domains
You can register custom domain constraints for your specific industry:
from sematryx import optimize
# Use with domain hint
result = optimize(
objective_function=my_objective,
bounds=bounds,
domain='financial', # Domain hint for better strategy selection
domain_config={
'max_risk': 0.15,
'compliance_level': 'strict'
}
)🎉 Next Steps
You now know how to use domain-specific optimization. Finally, learn advanced strategies for complex scenarios.