Skip to content

Instantly share code, notes, and snippets.

@rndmcnlly
rndmcnlly / Optimization.ipynb
Created April 18, 2017 18:14
Tutorial from a lecture on Modeling Optimization Problems in an Applied Answer Set Programming course at UC Santa Cruz (Spring 2017)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rndmcnlly
rndmcnlly / interstellar.lp
Created June 2, 2014 18:53
ASP model of space trading simulation game (gringo 3 w/ lua)
#begin_lua function min(a,b) return math.min(a,b) end #end_lua.
%% Adam's minimal event calculus formalism:
%% - only true holds/happens are tracked
%% - all fluents are always inertial
%% - time is a totally ordered contiguous integer sequence
%% - events and fluents are self-contained terms
%% - T variables always come first for easy sorting
initiated(T,F) :- happens(T,E), initiates(T,E,F).
@rndmcnlly
rndmcnlly / Playing with Sample Data.ipynb
Created January 19, 2014 12:43
Using IPython Notebook and PyMC to play around with some probabilistic graphical models. We're looking at ways of doing some serious machine learning *during gameplay* in the next version of DragonBox Adaptive.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#begin_lua
function collect(pred,arity)
local t = {}
Assignment.begin(pred,arity)
while Assignment.next() do
if Assignment.isTrue() then
table.insert(t,Assignment.args())
end
@rndmcnlly
rndmcnlly / lazy_graph.lp
Created July 23, 2013 00:01
A demonstration of automatic decomposition of universally quantified constraints according to the "disjunctive embedding" pattern. Constraints are specified as facts in the forall(Bindings,Expression) predicate. In this example, I encode the reflexivity, symmetry, and transitivity aspects of the definition of an equality relation in a simple gra…
#begin_lua
function args(t)
if Val.type(t) == Val.FUNC then
local res = t:args()
res.n = nil
return res
else
return {}
end
end
@rndmcnlly
rndmcnlly / uq_demo.lp
Last active December 20, 2015 02:49
A demonstration of manually applying the "disjunctive embedding" pattern to a transitive closure problem. The pattern replaces a normal rule with a cubic number of groundings with more complex rules requiring only quadratic groundings. In general, the pattern changes the worst-case number of groundings from O(n^|unique_vars_in_rule|) to O(n^max_…
node(1..100).
1 { arc(A,B):node(A):node(B) }.
%arc(A,C) :- arc(A,B), arc(B,C).
%% intent: forall( nodes(a,b,c), implies( and(arc(a,b), arc(b,c)), arc(a,c) ) ).
var(a;b;c).
bind(V,N):node(N) :- var(V).
bot :- bind(a,A), bind(b,B), not arc(A,B).
@rndmcnlly
rndmcnlly / coin_flip.lua
Created May 30, 2013 21:53
# airscript
-- Sample script to make an HTTP request with query parameters
local response = http.request {
url = 'http://www.random.org/integers/',
params = {
num=1, min=0, max=1, format='plain',
rnd='new', col=1, base=10
}
}
if tonumber(response.content) == 0 then
return 'heads'
@rndmcnlly
rndmcnlly / run.java
Created July 29, 2012 02:40
renderscript audio synthesis demo
// this is a snippet from RSAudioDemoActivity#run
Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);
short samples[] = new short[BLOCK_FRAMES];
Allocation out = Allocation.createSized(renderScript, Element.I16(renderScript), samples.length, Allocation.USAGE_SCRIPT);
synth.set_block_frames(BLOCK_FRAMES);
synth.bind_block_out(out);
synth.set_sample_rate(SAMPLE_RATE_IN_HZ);