package holeg.power_flow; public class PowerFlowProblem { public final Bus[] buses; public final Line[] lines; public final double scaleVoltage; public final double scalePower; public PowerFlowProblem(Bus[] buses, Line[] lines, double scaleVoltage, double scalePower) { if (buses == null) throw new IllegalArgumentException("buses is null"); if (lines == null) throw new IllegalArgumentException("lines is null"); this.buses = buses; this.lines = lines; this.scaleVoltage = scaleVoltage; this.scalePower = scalePower; } public boolean checkForValidData() { // Check per unit scale if (scaleVoltage <= 0) return false; if (scalePower <= 0) return false; // Check buses boolean slackBusFound = false; for (int i = 0; i < buses.length; i++) { Bus bus = buses[i]; if (bus == null) return false; // Invalid voltage if (bus.voltage <= 0) return false; // Check for multiple slack buses if (bus.type == BusType.Slack) { if (slackBusFound) return false; slackBusFound = true; } } // No slack bus if (!slackBusFound) return false; // Check lines for (int i = 0; i < lines.length; i++) { Line line = lines[i]; if (line == null) return false; // Invalid index of to/from if (line.to < 0 || line.to >= buses.length) return false; if (line.from < 0 || line.from >= buses.length) return false; // Invalid values for R and X if (line.R < 0 || line.X < 0) return false; } return true; } }