Z3 adding new variables during execution - z3

I'm trying to add a new feature to Z3.
This feature requires me to add new slack variables during execution and after pre-proccessing.
I could not find a proper way to this and I fear that attempting to force it by adding a new column will "break" the solver.
Is there a common recommended way to do that?
Thanks,
Omer

You can find an example in the file src/smt/theory_arith_int.h, method: mk_gomory_cut.
In the end of this method, a new polynomial constraint is created, and stored in the variable bound. Then, the following piece of code is used to "internalize" the constraint:
literal l = null_literal;
context & ctx = get_context();
ctx.internalize(bound, true);
l = ctx.get_literal(bound);
The method internalize will callback theory_arith, and a new slack is created.
Remark: the method internalize assumes the polynomial constraint stored in bound is in simplified form.

Related

Why DAC class is not saved in Acumatica?

Let's say I have following code:
DacClass cl = new DacClass();
//init fields of DacClass()
this.Persist();
but when I run this code in any graph, I'm getting different errors. Why?
You can't create DAC item in db in current graph. As mentioned in T200 manual you should create instance of graph and in created instance to call method persist. Another option is to use method PXDataBase.Insert. The first option is preferable for case if you need insertion with graph logic. The second option is preferable for cases if you need perfomance.

Rails - Difference between accessing model information via send() vs index

I have a model M that has a column C. At a certain point in my project I have a specific instance of M stored in memory, m. I also have the string "c", and I have found that both of these lines do the same thing (as far as I can tell):
m.send("c")
m["c"]
Is there a difference? Is there any reason to use one over the other?
P.S. - If you can come up with a better title, please comment, I had a hard time making an appropriate title.
You should just be using:
m.c
m["c"] is a shortcut for m.attributes['c'].
m.send("c") is used when you need to construct the method name to call dynamically:
index_type = "chapter"
m.send("open_to_#{index_type}", 1) # calls m.open_to_chapter(1)

How to create Linkedhashset using Hashset?

I was asked this question during my interview "How to create Linkedhashset using Hashset ?" anyone knows the answer ?
The LinkedHashSet class has a public LinkedHashSet(Collection<? extends E> c) constructor, so you could do
HashSet<Foo> hs = new HashSet<Foo>();
// add items...
LinkedHashSet<Foo> lhs = new LinkedHashSet<Foo>(hs);
to get a LinkedHashSet instance with the same content as hs. Note that there is no guarantee that the items from hs are inserted into lhs in the same order they were inserted into hs, since that information was never saved by hs.
There is no way to make "an HashSet which behaves like LinkedHashSet", that is, an instance of runtime class HashSet that behaves like a LinkedHashSet instance. However, you could do
HashSet<Foo> hs = new LinkedHashSet<Foo>();
which would give you an instance that would be seen by the outside world as a plain HashSet but use the LinkedHashSet implementation internally. I fail to see why you would ever want to do that, though - you would only gain a bunch of overhead and no added functionality, since the declared type is HashSet. The reason you'd want to use a LinkedHashSet in the first place is to be guaranteed the predictable iteration order, but you still wouldn't be able to assume that for hs - you could assign hs = new HashSet<Foo>() at any time, for instance.

Jena throwing ConversionException when trying to cast to OntClass

I have a particular Class URI for which I am trying to get an OntClass. The model is a regular model.
I wrote some code to find out whether the right statements were in the model, and it seems that they are so I can't understand why it won't let me view this as an OntClass. (tblURI is a String passed as a method parameter)
Resource tblR = m.createResource(tblURI);
List<Statement> prp = tblR.listProperties().toList();
for(Statement s : prp)
System.out.println(s);
System.out.println(tblR.canAs(OntClass.class));
OntClass tbl = tblR.as(OntClass.class);
This is the output:
[kps:datasource/EnsembleMS#translation_stable_id, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Class]
[kps:datasource/EnsembleMS#translation_stable_id, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2000/01/rdf-schema#Class]
[kps:datasource/EnsembleMS#translation_stable_id, http://www.w3.org/2000/01/rdf-schema#isDefinedBy, kps:datasource/EnsembleMS]
[kps:datasource/EnsembleMS#translation_stable_id, http://www.w3.org/2000/01/rdf-schema#label, "translation_stable_id"]
false
com.hp.hpl.jena.ontology.ConversionException: Cannot convert node kps:datasource/EnsembleMS#translation_stable_id to OntClass: it does not have rdf:type owl:Class or equivalent
at com.hp.hpl.jena.ontology.impl.OntClassImpl$1.wrap(OntClassImpl.java:81)
at com.hp.hpl.jena.enhanced.EnhNode.convertTo(EnhNode.java:155)
at com.hp.hpl.jena.enhanced.EnhNode.convertTo(EnhNode.java:34)
at com.hp.hpl.jena.enhanced.Polymorphic.asInternal(Polymorphic.java:66)
at com.hp.hpl.jena.enhanced.EnhNode.as(EnhNode.java:110)
at com.KPS.myApp.exampleMethod(myApp.java:123)
Why is it throwing an exception and how can I get an OntClass for the resource with uri tblURI?
Thanks for any pointers
You don't say what kind of model m is. In particular, if m was created with the RDFS language profile, the OntModel will be looking for an rdf:type of rdfs:Class, not owl:Class. If that's not the issue, then a complete minimal (i.e. runnable) example would help.
By the way, there's another problem I can see: resource URI's in the model should be in absolute form, not abbreviated form. The fact that you've got q-name URI's in your model, like kps:datasource/EnsembleMS#translation_stable_id, suggest that something is going wrong with your prefix handling. That won't by itself cause the problem you've reported, but it's a red flag to investigate.
Update
Responding to questions:
yes, you need to be using an OntModel, otherwise it's not possible for the OntClass to know which langauge profile to use. Either create the model as OntModel in the first place:
OntModel m = modelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
or wrap your plain model as an OntModel:
OntModel om = modelFactory.createOntologyModel( OntModelSpec.OWM_MEM, m );
Of course, you many use any of the model specifications, as you please, OWL_MEM is just one option.
createResource will not expand prefixes for you. So, you should expand them yourself before creating the resource:
m.createResource( m.expandPrefix( "foo:bar" ) );
Of course, this requires the prefix "foo" to be registered as a prefix. This happens automatically if you read an RDF document that defines the prefix in its syntax, but otherwise can be done manually with setNsPrefix.

Way to deep traverse a Groovy object with dot in string using GPath

The situation I have is that I'm querying MongoDB with a string for a field that is more than one level deep in the object hierarchy. This query must be a string. So for example I'm querying for something like this in Groovy:
def queryField = 'a.b.c' //this is variable and can be different every time
def result = mongodb.collection.findOne([queryField:5])
The problem no arises that in the result I want to find the value of the nested field. With GPath I could go one level deep and get a's value doing this
def aObj = result."a" //or result["a"]
However I want to go deeper than that by doing something like this:
def queryField = "a.b.c" //this can change every time and is not always 'a.b.c'
def cObj = result[queryField] //since field is variable, can't just assume result.a.b.c
This does not work in Groovy right now. There is a bug logged here, but I was wondering if there is a better work around to use for this scenario that is a bit cleaner than me parsing the string by splitting on the dot and then building the object traversal. Note that "a.b.c" is variable and unknown at runtime (e.g. it could be "a.b.d").
Based on the bug/thread it would appear there are some ambiguity problems with supporting a dotted property accessor. Based on the mailing list thread it would seem that evaluating the queryField string would be your best bet:
def result = [a: [b: [c: 42]]]
def queryString = 'a.b.c'
def evalResult = Eval.x(result, 'x.' + queryString)
assert evalResult == 42
Script on Groovy Web Console
The mailing list thread is a little old, so there's a new-ish (since at least 1.7.2) Eval class that can help out with running small snippets that don't have a large binding.
Otherwise, you can split the string and recursively do property evaluations on the object, effectively reproducing a subset of GPath traversal behavior.

Resources