use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class Viktor method bounds.
/**
* Returns the bounds for the problem.
*
* @return bounds
*/
public final Bounds bounds() {
List<String> atoms = new ArrayList<String>(cols + 1);
for (int i = 0; i < cols; i++) {
atoms.add(String.valueOf(i));
}
atoms.add("a");
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
final TupleSet abound = f.setOf("a");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
b.bound(a[i][j], abound);
}
}
final TupleSet xbound = f.range(f.tuple(String.valueOf(0)), f.tuple(String.valueOf(cols - 1)));
for (int j = 0; j < cols; j++) {
b.bound(x[j], xbound);
b.boundExactly(j, f.setOf(String.valueOf(j)));
}
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class ConfigAssure method bounds.
/**
* Returns the bounds corresponding to the given ip address and subnet files.
*
* @return bounds corresponding to the given ip address and subnet files.
* @throws IOException if either of the files cannot be found or accessed
* @throws IllegalArgumentException if either of the files cannot be parsed
*/
public Bounds bounds(String ipAddrsFile, String subnetsFile) throws IOException {
final Map<String, NetNode> nodes = parseAddresses(ipAddrsFile);
final Map<NetNode, Subnet> subnets = parseSubnets(subnetsFile, nodes);
final Universe universe = universe(nodes.keySet());
final Bounds bounds = new Bounds(universe);
final TupleFactory factory = universe.factory();
// bind the integers
for (int i = 0; i < 32; i++) {
bounds.boundExactly(1 << i, factory.setOf(Integer.valueOf(1 << i)));
}
// bind the port relation exactly to the port names
bounds.boundExactly(port, factory.range(factory.tuple(universe.atom(0)), factory.tuple(universe.atom(nodes.keySet().size() - 1))));
// bind the unknown relation exactly to the port names of ports with
// unknown addresses or masks
final TupleSet unknownBound = factory.noneOf(1);
for (NetNode n : nodes.values()) {
if (!n.known()) {
unknownBound.add(factory.tuple(n.port));
}
}
bounds.boundExactly(unknown, unknownBound);
// bind the subnet relation exactly, choosing the first element of each
// subnet as the representative
final TupleSet subnetBound = factory.noneOf(2);
for (Map.Entry<NetNode, Subnet> entry : subnets.entrySet()) {
final NetNode rep = entry.getKey();
for (NetNode member : entry.getValue().members) {
subnetBound.add(factory.tuple(rep.port, member.port));
}
}
bounds.boundExactly(subnet, subnetBound);
// bind the addr relation so that each address is guaranteed to be
// between minAddr (121.96.0.0) and maxAddr (121.96.255.255), inclusive
final TupleSet lAddr = factory.noneOf(2), uAddr = factory.noneOf(2);
for (NetNode node : nodes.values()) {
if (node.varAddress) {
// unknown address
lAddr.addAll(portToBits(factory, node.port, minAddr));
uAddr.addAll(portToBits(factory, node.port, maxAddr));
} else {
// known address
final TupleSet portToAddrBits = portToBits(factory, node.port, node.address);
lAddr.addAll(portToAddrBits);
uAddr.addAll(portToAddrBits);
}
}
bounds.bound(addr, lAddr, uAddr);
// bind the group and groupMask relations so that all ports with the
// same interface on the same subnet are guaranteed to have the same
// mask
final TupleSet lMask = factory.noneOf(2), uMask = factory.noneOf(2), groupBound = factory.noneOf(2);
for (Subnet sub : subnets.values()) {
for (Map.Entry<NetNode, Set<NetNode>> entry : sub.groups.entrySet()) {
final NetNode rep = entry.getKey();
for (NetNode member : entry.getValue()) {
groupBound.add(factory.tuple(member.port, rep.port));
// remove a grouped member out of
nodes.remove(member.port);
// the addresses set
}
if (rep.varMask) {
// unknown mask for the representative
uMask.addAll(portToBits(factory, rep.port, 31));
} else {
// known mask for the representative
final TupleSet portToMaskBits = portToBits(factory, rep.port, rep.mask);
lMask.addAll(portToMaskBits);
uMask.addAll(portToMaskBits);
}
}
}
// of any subnet
for (NetNode ungrouped : nodes.values()) {
groupBound.add(factory.tuple(ungrouped.port, ungrouped.port));
if (ungrouped.varMask) {
// unknown mask for the representative
uMask.addAll(portToBits(factory, ungrouped.port, 31));
} else {
// known mask for the representative
final TupleSet portToMaskBits = portToBits(factory, ungrouped.port, ungrouped.mask);
lMask.addAll(portToMaskBits);
uMask.addAll(portToMaskBits);
}
}
bounds.bound(groupMask, lMask, uMask);
bounds.boundExactly(group, groupBound);
// ", unknown.size: " + unknownBound.size());
return bounds;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class ALG197 method bounds.
/**
* Returns the bounds the problem (axioms 1, 4, 9-11, last formula of 14-15, and
* first formula of 16-22).
*
* @return the bounds for the problem
*/
@Override
public final Bounds bounds() {
final Bounds b = super.bounds();
final TupleFactory f = b.universe().factory();
final TupleSet op1h = b.upperBound(op1).clone();
final TupleSet op2h = b.upperBound(op2).clone();
// axiom
final TupleSet op1l = f.setOf(f.tuple("e16", "e16", "e15"));
// 14,
// line
// 6
// axiom
final TupleSet op2l = f.setOf(f.tuple("e26", "e26", "e25"));
// 15,
// line
// 6
op1h.removeAll(f.area(f.tuple("e16", "e16", "e10"), f.tuple("e16", "e16", "e16")));
op1h.addAll(op1l);
op2h.removeAll(f.area(f.tuple("e26", "e26", "e20"), f.tuple("e26", "e26", "e26")));
op2h.addAll(op2l);
b.bound(op1, op1l, op1h);
b.bound(op2, op2l, op2h);
final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e15", "e26"));
// first line of axioms 16-22
for (int i = 0; i < 7; i++) {
Tuple t = f.tuple("e16", "e2" + i);
high.add(t);
b.bound(h[i], f.setOf(t), high);
high.remove(t);
}
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class GEO158 method bounds.
/**
* Returns a bounds with the given number of maximum curves and points
*
* @return a bounds with the given number of maximum curves and points
*/
public Bounds bounds(int scope) {
assert scope > 0;
List<String> atoms = new ArrayList<String>(scope);
for (int i = 0; i < scope; i++) atoms.add("c" + i);
for (int i = 0; i < scope; i++) atoms.add("p" + i);
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
final TupleSet c = f.range(f.tuple("c0"), f.tuple("c" + (scope - 1)));
final TupleSet p = f.range(f.tuple("p0"), f.tuple("p" + (scope - 1)));
final TupleSet cc = c.product(c), pc = p.product(c);
b.bound(curve, c);
b.bound(point, p);
b.bound(partOf, cc);
b.bound(incident, pc);
b.bound(sum, c.product(cc));
b.bound(endPoint, pc);
b.bound(innerPoint, pc);
b.bound(meet, pc.product(c));
b.bound(closed, c);
b.bound(open, c);
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class GRA013_026 method bounds.
/**
* Returns the bounds.
*
* @return the bounds
*/
public final Bounds bounds() {
final List<String> atoms = new ArrayList<String>(graphSize);
for (int i = 1; i <= graphSize; i++) atoms.add("n" + i);
atoms.add("goal");
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
b.bound(goal, f.setOf("goal"));
final TupleSet ns = f.range(f.tuple("n1"), f.tuple("n" + graphSize));
b.boundExactly(node, ns);
final TupleSet s = f.noneOf(2);
for (int i = 1; i < graphSize; i++) {
for (int j = i + 1; j < graphSize; j++) s.add(f.tuple("n" + i, "n" + j));
}
b.boundExactly(lessThan, s);
b.bound(red, s);
b.bound(green, s);
return b;
}
Aggregations