Example usage for java.util Hashtable forEach

List of usage examples for java.util Hashtable forEach

Introduction

In this page you can find the example usage for java.util Hashtable forEach.

Prototype

@SuppressWarnings("unchecked")
    @Override
    public synchronized void forEach(BiConsumer<? super K, ? super V> action) 

Source Link

Usage

From source file:sample.piecewise.IEEE14BusSample.java

public static void main(String args[]) throws Exception {
    // initialize InterPSS plugin
    IpssCorePlugin.init();//from  w ww. ja v  a 2 s  .  c  om

    // =========== Aclf Network data preparation =====================//
    /*
     * The network diagram can be found at https://drive.google.com/drive/folders/0BzjeDvtdQBeyZTA5YTE4NGItMDIwMS00OGYzLTkyNGItOTNlZjM1YTEwMTEw
     */

    // Load the sample network
    AclfNetwork net = CorePluginObjFactory.getFileAdapter(IpssFileAdapter.FileFormat.IpssInternal)
            .load("testdata/ieee14.ipssdat").getAclfNet();

    // calculate loadflow
    LoadflowAlgorithm algo = CoreObjectFactory.createLoadflowAlgorithm(net);
    algo.loadflow();
    //System.out.println(net.net2String());

    // Turn all loads to Constant-Z load to create a linear network
    net.getBusList().forEach(bus -> {
        if (bus.isLoad())
            bus.setLoadCode(AclfLoadCode.CONST_Z);
    });

    // ============ Solve network voltage by piecewise algo ====================//

    // define the cutting branch set
    CuttingBranch[] cuttingBranches = new CuttingBranch[] { new CuttingBranch("4->71(1)"),
            new CuttingBranch("4->91(1)"), new CuttingBranch("5->61(1)") };

    // define bus injection current calculation function
    Function<AclfBus, Complex> injCurrentFunc = bus -> { // this function calculates bus injection current
        // The bus injection current is based on gen bus load flow results.
        return bus.isGen() ? bus.getNetGenResults().divide(bus.getVoltage()) : new Complex(0.0, 0.0);
    };

    // define a piecewise algo object and calculate the network bus voltage
    Hashtable<String, Complex> voltages = new PiecewiseAlgorithmImpl(net).calculateNetVoltage(cuttingBranches,
            injCurrentFunc);

    // output network bus voltage
    voltages.forEach((busId, voltage) -> {
        System.out.println("Bus id:" + busId + ", v = " + ComplexFunc.toStr(voltage));
    });
    /* you should see output like the following
     Bus id:10, v = 0.84642 + j0.39398
     Bus id:1, v = 0.93198 + j0.68774
     ...
     */
}