Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2010-2023, Danilo Pianini and contributors
* listed, for each module, in the respective subproject's build.gradle.kts file.
*
* This file is part of Alchemist, and is distributed under the terms of the
* GNU General Public License, with a linking exception,
* as described in the file LICENSE in the Alchemist distribution's top directory.
*/
package it.unibo.alchemist.model.sapere.conditions;
import it.unibo.alchemist.model.sapere.dsl.impl.ListTreeNode;
import it.unibo.alchemist.model.sapere.dsl.impl.NumTreeNode;
import it.unibo.alchemist.model.sapere.dsl.impl.Type;
import it.unibo.alchemist.model.sapere.dsl.impl.UIDNode;
import it.unibo.alchemist.model.sapere.dsl.IExpression;
import it.unibo.alchemist.model.sapere.dsl.ITreeNode;
import it.unibo.alchemist.model.conditions.AbstractCondition;
import it.unibo.alchemist.model.sapere.molecules.LsaMolecule;
import it.unibo.alchemist.model.sapere.ILsaCondition;
import it.unibo.alchemist.model.sapere.ILsaMolecule;
import it.unibo.alchemist.model.sapere.ILsaNode;
import it.unibo.alchemist.model.Node;
import it.unibo.alchemist.model.Reaction;
import org.danilopianini.lang.HashString;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
*/
public abstract class LsaAbstractCondition extends AbstractCondition> implements ILsaCondition {
private static final long serialVersionUID = -5633486241371700913L;
/**
* @param node
* the node hosting this action
* @param m
* the set of molecules on which this actions act
*/
public LsaAbstractCondition(final ILsaNode node, final Set m) {
super(node);
for (final ILsaMolecule mol : m) {
declareDependencyOn(mol);
}
}
@Override
public abstract String toString();
@Override
public final ILsaNode getNode() {
return (ILsaNode) super.getNode();
}
@Override
public abstract LsaAbstractCondition cloneCondition(Node> node, Reaction> reaction);
/**
* @param partialInstance
* the template, possibly partly instanced
* @param duplicateVariables
* true if partialInstance contains the same variable multiple
* times
* @param lsaSpace
* the LSA space of the node on which this function is working on
* @param alreadyRemoved
* the list of the molecules already removed from this node.
* @return the list of molecules in this LSA space that match the
* partialInstance, excluding all those which have been already
* removed.
*/
protected static List calculateMatches(
final List partialInstance,
final boolean duplicateVariables,
final List lsaSpace,
final List alreadyRemoved
) {
final List l = new ArrayList<>(lsaSpace.size() - alreadyRemoved.size());
for (final ILsaMolecule matched : lsaSpace) {
if (matched.matches(partialInstance, duplicateVariables)
&& countElements(lsaSpace, matched) > countElements(alreadyRemoved, matched)) {
l.add(matched);
}
}
return l;
}
private static int countElements(final Collection l, final T o) {
int count = 0;
for (final T t : l) {
if (t.equals(o)) {
count++;
}
}
return count;
}
/**
* @param template
* the template molecule
* @param node
* the node on which this function is working
* @param matchesList
* the list of matches to populate (theoretically, it should
* always be empty when calling this method)
* @param retrieved
* the list of the molecules removed from each node
* (theoretically, it should always be empty when calling this
* method)
*/
protected static void createMatches(
final ILsaMolecule template,
final ILsaNode node,
final List