Search in sources :

Example 6 with ProcessLink

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

the class ProductSystemWriter method exchangeIDs.

/**
 * Creates a map exchangeID -> internalID of the exchanges used in the
 * product system links.
 */
private TLongLongHashMap exchangeIDs(ProductSystem system) {
    var map = new TLongLongHashMap();
    if (system.referenceExchange != null) {
        map.put(system.referenceExchange.id, -1);
    }
    for (ProcessLink link : system.processLinks) {
        map.put(link.exchangeId, -1L);
    }
    try {
        String sql = "select id, internal_id from tbl_exchanges";
        NativeSql.on(exp.db).query(sql, r -> {
            long id = r.getLong(1);
            long internal = r.getLong(2);
            if (map.containsKey(id)) {
                map.put(id, internal);
            }
            return true;
        });
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(getClass());
        log.error("Failed to query exchange IDs", e);
    }
    return map;
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) Logger(org.slf4j.Logger)

Example 7 with ProcessLink

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

the class GraphEditor method createNecessaryLinks.

public void createNecessaryLinks(ProcessNode node) {
    MutableProcessLinkSearchMap linkSearch = node.parent().linkSearch;
    ProductSystemNode sysNode = node.parent();
    long id = node.process.id;
    for (ProcessLink pLink : linkSearch.getLinks(id)) {
        boolean isProvider = pLink.providerId == id;
        long otherID = isProvider ? pLink.processId : pLink.providerId;
        ProcessNode otherNode = model.getProcessNode(otherID);
        if (otherNode == null)
            continue;
        ProcessNode outNode = null;
        ProcessNode inNode = null;
        FlowType type = sysNode.flows.type(pLink.flowId);
        if (type == FlowType.PRODUCT_FLOW) {
            outNode = isProvider ? node : otherNode;
            inNode = isProvider ? otherNode : node;
        } else if (type == FlowType.WASTE_FLOW) {
            outNode = isProvider ? otherNode : node;
            inNode = isProvider ? node : otherNode;
        }
        if (outNode == null)
            continue;
        if (!outNode.isExpandedRight() && !inNode.isExpandedLeft())
            continue;
        Link link = new Link();
        link.outputNode = outNode;
        link.inputNode = inNode;
        link.processLink = pLink;
        link.link();
    }
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) MutableProcessLinkSearchMap(org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap) FlowType(org.openlca.core.model.FlowType) Link(org.openlca.app.editors.graphical.model.Link) ProcessLink(org.openlca.core.model.ProcessLink)

Example 8 with ProcessLink

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

the class ReconnectLinkCommand method execute.

@Override
public void execute() {
    ProductSystemNode systemNode = sourceNode.parent();
    oldLink.unlink();
    systemNode.getProductSystem().processLinks.remove(oldLink.processLink);
    systemNode.linkSearch.remove(oldLink.processLink);
    var processLink = new ProcessLink();
    processLink.providerId = sourceNode.process.id;
    processLink.setProviderType(sourceNode.process.type);
    processLink.flowId = oldLink.processLink.flowId;
    processLink.processId = targetNode.parent().process.id;
    processLink.exchangeId = targetNode.exchange.id;
    systemNode.getProductSystem().processLinks.add(processLink);
    systemNode.linkSearch.put(processLink);
    link = new Link();
    link.outputNode = sourceNode;
    link.inputNode = targetNode.parent();
    link.processLink = processLink;
    link.link();
    systemNode.editor.setDirty();
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) Link(org.openlca.app.editors.graphical.model.Link) ProcessLink(org.openlca.core.model.ProcessLink)

Example 9 with ProcessLink

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

the class TreeLayout method build.

private void build(ProductSystem productSystem, Node[] nodes) {
    List<Node> children = new ArrayList<>();
    for (Node node : nodes) {
        long processId = node.processId;
        for (ProcessLink link : linkSearch.getLinks(processId)) {
            if (link.processId != processId)
                continue;
            long providerId = link.providerId;
            if (containing.get(providerId) != null)
                continue;
            Node child = new Node();
            child.processId = providerId;
            node.leftChildren.add(child);
            containing.put(child.processId, 1);
            children.add(child);
        }
    }
    if (children.size() > 0)
        build(productSystem, children.toArray(new Node[children.size()]));
    children.clear();
    for (Node node : nodes) {
        long processId = node.processId;
        for (ProcessLink link : linkSearch.getLinks(processId)) {
            if (link.providerId != processId)
                continue;
            long recipientId = link.processId;
            if (containing.get(recipientId) != null)
                continue;
            Node child = new Node();
            child.processId = recipientId;
            node.rightChildren.add(child);
            containing.put(child.processId, 1);
            children.add(child);
        }
    }
    if (children.size() > 0)
        build(productSystem, children.toArray(new Node[children.size()]));
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ArrayList(java.util.ArrayList)

Example 10 with ProcessLink

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

the class LinkUpdate method linkOf.

private ProcessLink linkOf(ProcessDescriptor process, long exchangeId) {
    if (keepExisting) {
        var old = oldLinks.get(exchangeId);
        if (old != null)
            return old;
    }
    var exchange = exchanges.get(exchangeId);
    if (exchange == null)
        return null;
    var providers = providerIndex.get(exchange.flowId);
    if (providers == null)
        return null;
    long providerId = 0;
    ProcessDescriptor provider = null;
    for (var it = providers.iterator(); it.hasNext(); ) {
        long candidateId = it.next();
        // only link default providers
        if (providerLinking == ProviderLinking.ONLY_DEFAULTS) {
            if (candidateId == exchange.defaultProviderId) {
                providerId = candidateId;
                break;
            }
            continue;
        }
        // set the candidate as provider if there is nothing better
        var candidate = processes.get(candidateId);
        if (candidate == null)
            continue;
        if (isBetterProvider(process, provider, candidate, exchange)) {
            provider = candidate;
            providerId = candidateId;
        }
    }
    if (providerId == 0)
        return null;
    var link = new ProcessLink();
    link.providerId = providerId;
    link.exchangeId = exchangeId;
    link.processId = process.id;
    link.providerType = ProcessLink.ProviderType.PROCESS;
    link.flowId = exchange.flowId;
    return link;
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor)

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