Search in sources :

Example 11 with ProcessLink

use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.

the class RemoveAllConnectionsAction method run.

@Override
public void run() {
    if (processNodes.size() == 0)
        return;
    ProductSystemNode systemNode = editor.getModel();
    List<Link> links = new ArrayList<>();
    // create new link search to avoid problems with missing entries before
    // ConnectionLink.unlink is called
    List<ProcessLink> pLinks = systemNode.getProductSystem().processLinks;
    MutableProcessLinkSearchMap linkSearch = new MutableProcessLinkSearchMap(pLinks);
    for (ProcessNode processNode : processNodes) {
        List<ProcessLink> processLinks = linkSearch.getLinks(processNode.process.id);
        for (ProcessLink link : processLinks) linkSearch.remove(link);
        for (Link link : processNode.links) if (!links.contains(link))
            links.add(link);
    }
    Command command = new DeleteLinkCommand(links);
    editor.getCommandStack().execute(command);
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) Command(org.eclipse.gef.commands.Command) DeleteLinkCommand(org.openlca.app.editors.graphical.command.DeleteLinkCommand) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ArrayList(java.util.ArrayList) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) MutableProcessLinkSearchMap(org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap) DeleteLinkCommand(org.openlca.app.editors.graphical.command.DeleteLinkCommand) Link(org.openlca.app.editors.graphical.model.Link) ProcessLink(org.openlca.core.model.ProcessLink)

Example 12 with ProcessLink

use of org.openlca.core.model.ProcessLink in project olca-app by GreenDelta.

the class RemoveSupplyChainAction method collectSupplyChain.

private void collectSupplyChain(long processId) {
    ProductSystemNode systemNode = editor.getModel();
    ProcessNode node = systemNode.getProcessNode(processId);
    List<ProcessLink> incomingLinks = linkSearch.getConnectionLinks(processId);
    for (ProcessLink link : incomingLinks) {
        if (node != null) {
            Link l = node.getLink(link);
            if (l != null)
                connections.add(l);
            else
                links.add(link);
        } else {
            links.add(link);
        }
        linkSearch.remove(link);
        if (linkSearch.getProviderLinks(link.providerId).size() == 0) {
            collectSupplyChain(link.providerId);
            ProcessNode providerNode = editor.getModel().getProcessNode(link.providerId);
            if (providerNode != null)
                nodes.add(providerNode);
            else
                processIds.add(link.providerId);
        }
    }
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) Link(org.openlca.app.editors.graphical.model.Link) ProcessLink(org.openlca.core.model.ProcessLink)

Example 13 with ProcessLink

use of org.openlca.core.model.ProcessLink in project olca-modules by GreenDelta.

the class SystemExport method mapLinks.

private void mapLinks(Model model) {
    Technology tech = Models.forceTechnology(model);
    Map<Long, ProcessInstance> instances = new HashMap<>();
    for (Long id : system.processes) {
        if (id == null)
            continue;
        ProcessInstance pi = initProcessInstance(id);
        instances.put(id, pi);
        tech.processes.add(pi);
    }
    for (ProcessLink link : system.processLinks) {
        FlowDescriptor flow = flows.get(link.flowId);
        if (flow == null)
            continue;
        if (flow.flowType == FlowType.PRODUCT_FLOW) {
            ProcessInstance pi = instances.get(link.providerId);
            addLink(pi, link, flow);
        } else if (flow.flowType == FlowType.WASTE_FLOW) {
            ProcessInstance pi = instances.get(link.processId);
            addLink(pi, link, flow);
        }
    }
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) Technology(org.openlca.ilcd.models.Technology) HashMap(java.util.HashMap) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessInstance(org.openlca.ilcd.models.ProcessInstance)

Example 14 with ProcessLink

use of org.openlca.core.model.ProcessLink in project olca-modules by GreenDelta.

the class DQResultTest method createProductSystem.

private void createProductSystem() {
    system = ProductSystem.of(process1);
    system.targetAmount = 1;
    system.processes.add(process1.id);
    system.processes.add(process2.id);
    ProcessLink link = new ProcessLink();
    link.flowId = pFlow2.id;
    link.providerId = process2.id;
    for (Exchange e : process1.exchanges) {
        if (e.flow.id == pFlow2.id)
            link.exchangeId = e.id;
    }
    link.processId = process1.id;
    system.processLinks.add(link);
    system = db.insert(system);
}
Also used : Exchange(org.openlca.core.model.Exchange) ProcessLink(org.openlca.core.model.ProcessLink)

Example 15 with ProcessLink

use of org.openlca.core.model.ProcessLink in project olca-modules by GreenDelta.

the class CostTests method testAddCostsForSameProduct.

@Test
public void testAddCostsForSameProduct() {
    Process p1 = TestProcess.refProduct("p1", 1, "kg").addCosts("p1", 1, "EUR").prodIn("p1", 0.5, "kg").elemIn("water", 1, "m3").get();
    long exchangeId = -1;
    for (Exchange e : p1.exchanges) {
        if (e.flow.name.equals("p1") && e.isInput) {
            e.costs = 0.4d;
            e.currency = p1.quantitativeReference.currency;
            exchangeId = e.id;
            break;
        }
    }
    p1 = db.update(p1);
    ProductSystem system = TestSystem.of(p1).get();
    // add a link to the process itself
    ProcessLink selfLink = new ProcessLink();
    selfLink.flowId = p1.quantitativeReference.flow.id;
    selfLink.providerId = p1.id;
    selfLink.processId = p1.id;
    selfLink.exchangeId = exchangeId;
    system.processLinks.add(selfLink);
    system = db.update(system);
    FullResult r = TestSystem.calculate(system);
    Assert.assertEquals(-1.2, r.totalCosts(), 1e-10);
}
Also used : Exchange(org.openlca.core.model.Exchange) ProcessLink(org.openlca.core.model.ProcessLink) FullResult(org.openlca.core.results.FullResult) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) TestProcess(org.openlca.core.TestProcess) Test(org.junit.Test)

Aggregations

ProcessLink (org.openlca.core.model.ProcessLink)24 ProductSystemNode (org.openlca.app.editors.graphical.model.ProductSystemNode)7 Link (org.openlca.app.editors.graphical.model.Link)5 ProcessNode (org.openlca.app.editors.graphical.model.ProcessNode)5 Exchange (org.openlca.core.model.Exchange)5 FlowType (org.openlca.core.model.FlowType)5 Process (org.openlca.core.model.Process)4 ProductSystem (org.openlca.core.model.ProductSystem)4 MutableProcessLinkSearchMap (org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap)3 Flow (org.openlca.core.model.Flow)3 ArrayList (java.util.ArrayList)2 Command (org.eclipse.gef.commands.Command)2 Test (org.junit.Test)2 ProductSystemDao (org.openlca.core.database.ProductSystemDao)2 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)2 TLongLongHashMap (gnu.trove.map.hash.TLongLongHashMap)1 HashMap (java.util.HashMap)1 DeleteLinkCommand (org.openlca.app.editors.graphical.command.DeleteLinkCommand)1 MassCreationCommand (org.openlca.app.editors.graphical.command.MassCreationCommand)1 LayoutManager (org.openlca.app.editors.graphical.layout.LayoutManager)1