use of com.amazonaws.services.s3.model in project bmoth by hhu-stups.
the class Issue73Test method testSatPredicateWithoutModel.
@Test
public void testSatPredicateWithoutModel() throws IOException {
String formula = "1 < 2";
BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
SolutionFinder finder = new SolutionFinder(z3Solver, z3Context);
Set<Model> solutions = finder.findSolutions(constraint, 20);
assertEquals(0, solutions.size());
}
use of com.amazonaws.services.s3.model in project aws-doc-sdk-examples by awsdocs.
the class DisplayFaces method main.
public static void main(String[] arg) throws Exception {
// Change the value of bucket to the S3 bucket that contains your image file.
// Change the value of photo to your image file name.
String photo = "input.png";
String bucket = "bucket";
int height = 0;
int width = 0;
// Get the image from an S3 Bucket
AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();
com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, photo);
S3ObjectInputStream inputStream = s3object.getObjectContent();
BufferedImage image = ImageIO.read(inputStream);
DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)));
width = image.getWidth();
height = image.getHeight();
// Call DetectFaces
AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient();
DetectFacesResult result = amazonRekognition.detectFaces(request);
// Show the bounding box info for each face.
List<FaceDetail> faceDetails = result.getFaceDetails();
for (FaceDetail face : faceDetails) {
BoundingBox box = face.getBoundingBox();
float left = width * box.getLeft();
float top = height * box.getTop();
System.out.println("Face:");
System.out.println("Left: " + String.valueOf((int) left));
System.out.println("Top: " + String.valueOf((int) top));
System.out.println("Face Width: " + String.valueOf((int) (width * box.getWidth())));
System.out.println("Face Height: " + String.valueOf((int) (height * box.getHeight())));
System.out.println();
}
// Create frame and panel.
JFrame frame = new JFrame("RotateImage");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DisplayFaces panel = new DisplayFaces(result, image);
panel.setPreferredSize(new Dimension(image.getWidth() / scale, image.getHeight() / scale));
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}
use of com.amazonaws.services.s3.model in project batfish by batfish.
the class Encoder method verify.
/**
* Checks that a property is always true by seeing if the encoding is unsatisfiable. mkIf the
* model is satisfiable, then there is a counter example to the property.
*
* @return A VerificationResult indicating the status of the check.
*/
public Tuple<VerificationResult, Model> verify() {
EncoderSlice mainSlice = _slices.get(MAIN_SLICE_NAME);
int numVariables = _allVariables.size();
int numConstraints = _solver.getAssertions().length;
int numNodes = mainSlice.getGraph().getConfigurations().size();
int numEdges = 0;
for (Map.Entry<String, Set<String>> e : mainSlice.getGraph().getNeighbors().entrySet()) {
numEdges += e.getValue().size();
}
long start = System.currentTimeMillis();
Status status = _solver.check();
long time = System.currentTimeMillis() - start;
VerificationStats stats = null;
if (_question.getBenchmark()) {
stats = new VerificationStats();
stats.setAvgNumNodes(numNodes);
stats.setMaxNumNodes(numNodes);
stats.setMinNumNodes(numNodes);
stats.setAvgNumEdges(numEdges);
stats.setMaxNumEdges(numEdges);
stats.setMinNumEdges(numEdges);
stats.setAvgNumVariables(numVariables);
stats.setMaxNumVariables(numVariables);
stats.setMinNumVariables(numVariables);
stats.setAvgNumConstraints(numConstraints);
stats.setMaxNumConstraints(numConstraints);
stats.setMinNumConstraints(numConstraints);
stats.setAvgSolverTime(time);
stats.setMaxSolverTime(time);
stats.setMinSolverTime(time);
}
if (status == Status.UNSATISFIABLE) {
VerificationResult res = new VerificationResult(true, null, null, null, null, null, stats);
return new Tuple<>(res, null);
} else if (status == Status.UNKNOWN) {
throw new BatfishException("ERROR: satisfiability unknown");
} else {
VerificationResult result;
Model m;
while (true) {
m = _solver.getModel();
SortedMap<String, String> model = new TreeMap<>();
SortedMap<String, String> packetModel = new TreeMap<>();
SortedSet<String> fwdModel = new TreeSet<>();
SortedMap<String, SortedMap<String, String>> envModel = new TreeMap<>();
SortedSet<String> failures = new TreeSet<>();
buildCounterExample(this, m, model, packetModel, fwdModel, envModel, failures);
if (_previousEncoder != null) {
buildCounterExample(_previousEncoder, m, model, packetModel, fwdModel, envModel, failures);
}
result = new VerificationResult(false, model, packetModel, envModel, fwdModel, failures, stats);
if (!_question.getMinimize()) {
break;
}
BoolExpr blocking = environmentBlockingClause(m);
add(blocking);
Status s = _solver.check();
if (s == Status.UNSATISFIABLE) {
break;
}
if (s == Status.UNKNOWN) {
throw new BatfishException("ERROR: satisfiability unknown");
}
}
return new Tuple<>(result, m);
}
}
use of com.amazonaws.services.s3.model in project batfish by batfish.
the class PropertyChecker method checkDeterminism.
/*
* Check if there exist multiple stable solutions to the network.
* If so, reports the forwarding differences between the two cases.
*/
public AnswerElement checkDeterminism(HeaderQuestion q) {
Graph graph = new Graph(_batfish);
Encoder enc1 = new Encoder(_settings, graph, q);
Encoder enc2 = new Encoder(enc1, graph, q);
enc1.computeEncoding();
enc2.computeEncoding();
addEnvironmentConstraints(enc1, q.getBaseEnvironmentType());
BoolExpr relatedFailures = relateFailures(enc1, enc2);
BoolExpr relatedEnvs = relateEnvironments(enc1, enc2);
BoolExpr relatedPkts = relatePackets(enc1, enc2);
BoolExpr related = enc1.mkAnd(relatedFailures, relatedEnvs, relatedPkts);
BoolExpr required = enc1.mkTrue();
for (GraphEdge ge : graph.getAllRealEdges()) {
SymbolicDecisions d1 = enc1.getMainSlice().getSymbolicDecisions();
SymbolicDecisions d2 = enc2.getMainSlice().getSymbolicDecisions();
BoolExpr dataFwd1 = d1.getDataForwarding().get(ge.getRouter(), ge);
BoolExpr dataFwd2 = d2.getDataForwarding().get(ge.getRouter(), ge);
assert dataFwd1 != null;
assert dataFwd2 != null;
required = enc1.mkAnd(required, enc1.mkEq(dataFwd1, dataFwd2));
}
enc1.add(related);
enc1.add(enc1.mkNot(required));
Tuple<VerificationResult, Model> tup = enc1.verify();
VerificationResult res = tup.getFirst();
Model model = tup.getSecond();
SortedSet<String> case1 = null;
SortedSet<String> case2 = null;
Flow flow = null;
CounterExample ce = new CounterExample(model);
if (!res.isVerified()) {
case1 = new TreeSet<>();
case2 = new TreeSet<>();
flow = ce.buildFlow(enc1.getMainSlice().getSymbolicPacket(), "(none)");
for (GraphEdge ge : graph.getAllRealEdges()) {
SymbolicDecisions d1 = enc1.getMainSlice().getSymbolicDecisions();
SymbolicDecisions d2 = enc2.getMainSlice().getSymbolicDecisions();
BoolExpr dataFwd1 = d1.getDataForwarding().get(ge.getRouter(), ge);
BoolExpr dataFwd2 = d2.getDataForwarding().get(ge.getRouter(), ge);
assert dataFwd1 != null;
assert dataFwd2 != null;
boolean b1 = ce.boolVal(dataFwd1);
boolean b2 = ce.boolVal(dataFwd2);
if (b1 != b2) {
if (b1) {
String route = ce.buildRoute(enc1.getMainSlice(), ge);
String msg = ge + " -- " + route;
case1.add(msg);
}
if (b2) {
String route = ce.buildRoute(enc2.getMainSlice(), ge);
String msg = ge + " -- " + route;
case2.add(msg);
}
}
}
}
// Ensure canonical order
boolean less = (case1 == null || (case1.first().compareTo(case2.first()) < 0));
if (less) {
return new SmtDeterminismAnswerElement(flow, case1, case2);
} else {
return new SmtDeterminismAnswerElement(flow, case2, case1);
}
}
use of com.amazonaws.services.s3.model in project xtext-core by eclipse.
the class Bug305397Test method testBug.
@Test
public void testBug() throws Exception {
with(new Bug305397StandaloneSetup());
Model model = (Model) getModel(" a element \n element X end\n element Y end \nend");
Element outer = model.getElements().get(0);
Element firstInner = outer.getElements().get(0);
ICompositeNode outerNode = NodeModelUtils.getNode(outer);
assertEquals(3, outerNode.getOffset());
ICompositeNode firstInnerNode = NodeModelUtils.getNode(firstInner);
assertEquals(17, firstInnerNode.getOffset());
}
Aggregations