sbass unable to read gringo output - answer-set-programming

I'm running a simple ASP program:
%Defining possible states of each of the rook space
occupied(t; f).
%Generate all possible grids
{rook(X, Y, D) : occupied(D)} = 1 :- X=2..x, Y=2..y.
%Bound the grid with empty space
rook(X, Y, f) :- X=0, Y=1..y.
rook(X, Y, f) :- X=x+1, Y=1..y.
rook(X, Y, f) :- X=1..x, Y=0.
rook(X, Y, f) :- X=1..x, Y=y+1.
%Surrounding space is considered free path
freePath(X, Y) :- X=0, Y=1..y.
freePath(X, Y) :- X=x+1, Y=1..y.
freePath(X, Y) :- X=1..x, Y=0.
freePath(X, Y) :- X=1..x, Y=y+1.
%Generate empty path from the outside space
freePath(X, Y) :- rook(X, Y, f), freePath(X+1, Y).
freePath(X, Y) :- rook(X, Y, f), freePath(X-1, Y).
freePath(X, Y) :- rook(X, Y, f), freePath(X, Y-1).
freePath(X, Y) :- rook(X, Y, f), freePath(X, Y+1).
%Remove any grid where a rook is not adjacent to a free path
:- rook(X, Y, t), not freePath(X, Y+1),
not freePath(X, Y-1),
not freePath(X-1, Y),
not freePath(X+1, Y).
%Maximize the number of rooks by minimizing empty space
#maximize{1, X, Y : rook(X, Y, t)}.
#show rook/3.
In order to try to cut down the search space by breaking symmetries, I've been trying to use the sbass tool that's on Potassco's website
I'm using Ubuntu 20.04 LTS. After running make in the sbass file and getting the executable and I just run:
gringo ./rooks-game.lp -c x=5 -c y=5 | ./sbass
And it's throwing an error:
./sbass: unable to read input
What am I missing? According to the article, sbass should just be able to take the output of gringo.

Related

I would like to verify the divergence theorem in MATLAB

I would like to verify the divergence theorem if F(x, y, z) =<x^2y^2, y^2z^2 , z^2x^2> when the solid E is bounded by x^2 + y^2 + z^2 = 2 on top and z = (x^2+y^2)^1/2 on the bottom in MATLAB.
I know the function for the divergence but I need help with setting up the bounds.
syms x y z F(x,y,z)=[x^2y^2, y^2z^2, z^2x^2]; div=divergence(F,[x,y,z])
Thank you in advance!
try this
Divergence Theorem (Gauss’, Ostrogradsky’s) to Measure Flow
version 1.0.0 (2.62 KB) by Roche de Guzman
https://uk.mathworks.com/matlabcentral/fileexchange/70371-divergence-theorem-gauss-ostrogradsky-s-to-measure-flow?s_tid=srchtitle_divergence%2520theorem_2

Error in mesh(X,Y,Z) in matlab

This is my code:
load mwe16_2.dat;
x = mwe16_2(:,1); % x contains the 1st column(500 values) of ‘mwe16_2’
y = mwe16_2(:,2); % y contains the 2nd column (500 values)of ‘mwe16_2’
z = mwe16_2(:,3); % z contains the 3rd column(500 values) of ‘mwe16_2’
[X, Y, Z] = meshgrid (x, y, z);
mesh (X, Y, Z)
While running the code it is showing the error:
*Error in plot3_d (line 13) mesh(X,Y,Z) in Matlab*
Can someone say the reason for the error and how to correct it?
[X,Y,Z] = meshgrid(x,y,z) produces three 3D arrays from x, y and z vectors. Now if you take a look at mesh you will see that you are not providing this function with proper input.
If you want to illustrate the set of points defined by three vectors of x, y and z, you can consider using scatter3:
figure; scatter3(x, y, z)

ndgrid and interpn - matlab

I have 4 grids:
kgrid which is [77x1];
x which is [15x1];
z which is [9x1];
s which is [2x1];
Then I have a function V which is:
V [77x15x9x2]
I am trying to interpolate V at some kprime points. To do so, I am doing:
[ks, xs, zs, ss] = ndgrid(kgrid, x, z, s);
Vprime = interpn(xs, ks, zs, ss, V, xs, kprime, zs, ss, 'spline');
where kprime is a [77x15x9x2].
All the matrices needed (kgrid, x, z, s, V and kprime) can be found here: http://www.filedropper.com/grids
However I am getting this error when using
Error using griddedInterpolant
Data is not valid NDGRID format.
Error in interpn (line 149)
F = griddedInterpolant(X{:}, V, method,extrap);
Any clue on what could be the issue?
The order of the inputs to interpn need to be the same order as the outputs of your ndgrid call. You have flipped ks and xs.
vprime = interpn(ks, xs, zs, ss, V, kprime, xs, zs, ss);

Plotting 3-d graphs and level curves in Matlab

I have the following code below, but I cannot test it since I do not have Matlab with me right now and I am afraid I might not have the time to test it by myself when I finally get it. I'm trying to plot both 3-d graphs and graphs of the level curves in the y and x axis (two dimensions only) of three different types of functions. I would appreciate if someone could point if there is something wrong with the code below.
**************************************************************
**plotting functions -- level curves and 3d graph**
x_val = linspace(0, 100, 200);
y_val = linspace(0, 100, 200);
[x, y] = meshgrid(x_val, y_val);
z = ln(x).+y.;
figure
contour3(y, x, z)
contour(y, x, z)
********************************
z = (x.^1/2)+y.;
figure
contour3(y, x, z)
contour(y, x, z)
*********************************
z = (x.^1/3)+y.;
figure
contour3(y, x, z)
contour(y, x, z)
ln is not a valid matlab symbol, in addition to the excess of dots mentioned and comment formatting above. The following runs on Matlab.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%plotting functions -- level curves and 3d graph%%
x_val = linspace(0, 100, 200);
y_val = linspace(0, 100, 200);
[x, y] = meshgrid(x_val, y_val);
z = log(x)+y;
figure
contour3(y, x, z)
figure
contour(y, x, z)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z = (x.^1/2)+y;
figure
contour3(y, x, z)
figure
contour(y, x, z)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z = (x^1/3)+y;
figure
contour3(y, x, z)
figure
contour(y, x, z)
For starters, comments in MATLAB are "%" not "*".
You have a few mistakes, trying to do element-wise operators, I think.
Your three assignments of z have too many dots:
z = log(x)+y;
z = (x.^1/2)+y;
z = (x.^1/3)+y;
It is not necessary to use ".+", because MATLAB automatically adds matrices elementwise.

First, second and third derivative of a vector function

I can define the following vector function
f(x, y, z) = [x2 - 1, x3 + y2, z]
In MatLab or in Maple.
I want to find (and evaluate) the first, second and third derivatives of it. How to find: ∇f, ∇2f and ∇3f? Here vector function f is differentiated with respect to vector (x, y, z). I can do the simple job of finding ∇f with Maple as follows:
f(x, y, z) = [x2 - 1, x3 + y2, z]
∇f = Jacobian(f, [x, y, z])
But how to differentiate ∇f?
Is there a function in MatLab (or in Maple) which may take the above function as an input and evaluate its derivatives for a given value of (x, y, z)?