[GAP Forum] Re: [GAP Support] using gap from another program
Alastair Donaldson
ally at dcs.gla.ac.uk
Tue Mar 1 17:26:37 GMT 2005
I use GAP from JAVA by launching GAP in quiet mode as a slave process,
then communicating with GAP using a buffered writer (which GAP thinks is
standard input) and a buffered reader (which is where GAP's standard
output goes to).
Here's a trivial bit of JAVA code which will print out the size of the
group generated by (1,2)(3,4) and (5,6):
try {
// Launch GAP in 'quiet' mode
Process p =
Runtime.getRuntime().exec("/usr/local/data/group_files/newinstall/gap-linux
-L gapworkspace -q");
BufferedReader br = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));
// Send something to GAP
bw.write("G := Group((1,2)(3,4),(5,6));;\n";
bw.write("Size(G);\n");
bw.flush(); // You need to do this before you can read
anything back from GAP
System.out.println("The size of the group is " +
br.readLine());
} catch (Exception e) {
System.out.println("Error executing GAP");
System.out.println(e);
e.printStackTrace();
System.out.println(br.readLine());
System.exit(1);
}
}
I have some more complex examples where my JAVA program does some real
computation using GAP. I've found it really tricky to get GAP to
synchronise with my programs since GAP can produce rather unpredictable
output sometimes.
-Alastair
On Tue, 1 Mar 2005, David Joyner wrote:
> Nicolas:
>
> A very simple example of a python-gap interface is at
> http://cadigweb.ew.usna.edu/~wdj/gap/
> I don't know java, but perhaps that example will help you.
>
> I'm cross-posting to the Forum, in case there might be
> other GAP users interested as well.
>
> - David Joyner
>
> ++++++++++++++++++++++++++++
>
>
>
> Nicolas Demoulin wrote:
> > Hi,
> > I am a student in computer science from University College Cork and I am
> > doing a project on Symmetry Breaking in CSP. I have already used gap but
> > what I would like to do know is to insert gap in my main program which
> > is written in Java. And I saw in the faq that :
> >
> > "What you can do is to run GAP in a child process and communicate with
> > it using pipes, pseudo-ttys, UNIX FIFOs or some similar device. We have
> > done this successfully in a number of projects, and you can contact the
> > support list for more detailed advice if you want to go down this route"
> >
> > So if you can give me advice or examples of communication between gap
> > and another program, it will help me very much.
> >
> > Thank you to have taken time to read me
> > Best Regards
> >
> > Nicolas Demoulin
> >
> > _________________________________________________________________
> > Nouveau MSN Hotmail : créez une adresse @hotmail.fr qui vous ressemble !
> > http://www.msn.fr/newmsnhotmail
> >
> > _______________________________________________
> > Support mailing list
> > Support at gap-system.org
> > http://mail.gap-system.org/mailman/listinfo/support
>
>
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum
>
More information about the Forum
mailing list