I am trying to develop NetLogo model (consumer research), but I would like more control over what agents (turtles) are and what they can do, therefore I would like to write code in Java, import Java libraries, possibly, use rules engine and so on. Is that possible in NetLogo?
If not, then what other agent modelling frameworks with Java programming capabilities are?
It is possible with NetLogo using the Extensions API. With this API, you write your overall model in NetLogo, making calls into your Java-based routines as needed. (You cannot call a Java library directly from NetLogo code; rather, you write an extension that exposes the routines in that library as NetLogo primitives, and then you use those primitives in your model.) A look at the NetLogo extensions download page should give you an idea of the diverse sorts of things are possible with this API.
See also: Integrating NetLogo and Java : when should we think about this integration as a good option?.
Two notable agent-based modeling frameworks where you write your entire model in Java are Repast and MASON.
Related
I am a bit newbie in the topic of Netlogo simulations.
I am gathering information about invoking different traffic simulators.
Is Netlogo have the possibility to receive a call from the Java side via a library that controls agents or the traffic flow or has some extension able to handle it by some external logic?
For example, the SUMO simulator is fully designed for traffic simulations, and it is pretty easy to control it using TraCI connection.
Is there a possibility to write a similar grid simulation in NetLogo using only Java/Python/C++ code, or NetLogo simulator requires a clear Logo-semantic code in the NetLogo interface?
My comparison is caused by my investigation of specific solutions performance that use command-line, library or API. It seems NetLogo requires Logo-inspired code, which simulates processes with a GUI interface. GUI in this system appears to be a considerable slowdown...
As it lacks a communication interface and seems to be a single-threaded GUI-based simulator, I thought it is used mainly for elementary simulations.
Am I correct with this assumption? Is it a logo-inspired interpreter that cannot be used in large scale distributed systems and is usually used for a student-showcase purpose?
You don't need to use the NetLogo GUI; you can run simulations purely from the command line, as documented here: http://ccl.northwestern.edu/netlogo/docs/behaviorspace.html#advanced-usage
It's actually very common for researchers to do this, typically so they can run experiments on a cluster. Hundreds of research papers have been published using NetLogo as basis for doing simulations. NetLogo is also a teaching tool, but it would be very far from the truth to describe it as only for "student showcase" purposes.
The NetLogo language itself is single-threaded, but BehaviorSpace supports doing multiple simulation runs in parallel (in the GUI or on the command line, either way).
I don't know what you mean by “lacks a communication interface”; I think you're misinformed there. NetLogo can be and has been connected to many other tools and systems, and is extensible via Java APIs.
But do you have to write your simulation in the NetLogo language, which is a dialect of Logo? Yes, you do. The language can be augmented via the extensions API, but if you want to avoid NetLogo-the-language entirely, then NetLogo isn't a good choice.
NetLogo can communicate with Java, R, Mathematica, not sure what else. But NetLogo is not suitable for building GUI interfaces, it provides the simulation engine. Not just student showcase, but I probably wouldn't use it above about 50,000 agents so not really for large scale distributed systems
I want to make a program that would be able to manipulate the desktop based on user input commands (Preferably by voice, but... baby steps). Similar to Windows Speech Recognition, or Cortana.
I would like to make this as easy as possible to use and set up etc. For this reason I had planned on writing it in Java so that it would be cross-platform, and as simple as possible for users.
After looking further into how I would go about this, I saw mentioned here (Manipulating windows from other applications in Java) that I should use JNI.
I'm now wondering if (as mentioned in the top comment) it would be easier if I were to switch to C++ as using JNI might negate the cross-platform capability benefits of Java?
Or if possible, would it be possible to have the program select the appropriate JNI classes automatically based on the operating system?
In short: Does JNI negate the benefits of Java cross-platform compatibility?
Sorry if this post is a bit confusing. I've quite a few questions so this may seem a bit all over the place.
Many Operating System specific tasks cannot be done platform independent. But what Java already does a lot and JNI allows you to do too is that you can have different native binaries for different platforms - and possibly a single Java API to use all of them platform-independent.
Going C++ has the disadvantage that you need to have multiple executables. With Java you could have just 1 that loads different native code.
Although if you need a lot of different native code to implement your idea, maybe it's easier to just implement it for just 1 platform directly in a language that has bindings to all the required native APIs. Like maybe C# for Windows and something else for other platforms?
In an environment with both .Net and Java code, it seems that one way to consolidate the two is to use (or at least look at) common interface files in order to share a high level understanding of the business logic in an organization.
Java and .Net are different from a technical perspective, but by sharing interfaces they can focus on common business logic, while leveraging the advantages of OOP.
Is it common in any sense for an organization to implement an architecture based on having interfaces that are applied to both .Net and Java code and would it be possible to create (or does one exist) a syntax converter for interface code, so they can be easily shared by both frameworks? Or are these two frameworks so completely different that it would be counterproductive to share interfaces?
See IKVM:
IKVM.NET is an implementation of Java for Mono and the Microsoft .NET Framework. It includes the following components:
A Java Virtual Machine implemented in .NET
A .NET implementation of the Java class libraries
Tools that enable Java and .NET interoperability
IKVM makes it possible to develop .NET applications that use Java API's. Here's how to proceed:
IKVM comes with an implementation of the Java class libraries in .NET. To use those API's, simply add a reference to IKVM.OpenJDK.ClassLibrary.dll to your Mono / .NET IDE project.
To use other Java API's, you can take one of the following approaches:
Convert the Java API to .NET CIL using ikvmc. This produces a .NET dll that you can reference in your project.
Use the Java reflection API's to dynamically load and execute the Java bytecode using the IKVM bytecode interpreter. For example, your application can load Java bytecode over a network connection and execute it dynamically.
http://www.ikvm.net/
As an experiment I am working on a small platform for Java applications (client server, P2P etc.) which I would like to be able to use from both Java and Scala. And possibly also from Groovy, jRuby etc.
I know that Scala can call easily into Java, but that Java cannot as easily call back into Scala. I don't know how this is working in jRuby and Groovy.
My initial thought was to implement the platform in Java, and then see if I could make it available to other languages. However, the platform may include starting threads which call components that implement certain Java interfaces. Would it be possible to pass e.g. a factory implemented in Scala, but which implements a Java interface, to a Java component and have that Java component call the Scala factory?
What are your recommendations in general for implementing such a cross language platform?
I am by no means an expert and have never done such a cross-language project (just minor Java/Scala).
But I would suggest implementing it in the language:
you know best
makes you most productive
ensures the most maintainability
In my case it would be Scala.
So what I would do is define the API in the form of Java interfaces, which I would then implement in Scala (probably I would need to convert Scala/Java collections back-and-forth, but that would be an implementation detail).
That way you make sure that other JVM languages can interact with your API, and you implement it in whatever language you are best.
Java can call Scala as easy at the other way around,
With eclipse you need to install 'Scala IDE' from the 'eclipse market place'
and configure the compiler to 'Scala Then Java' option in Properties->'Scala Compiler'-> 'Build Manager'-> compileorder.
P.s. you also need to add Scala nature to the project.
Would it be possible to pass e.g. a factory implemented in Scala, but which implements a Java interface, to a Java component and have that Java component call the Scala factory?
Even if it were so, switching to Scala would not solve the problem, as then jRuby would have even more problems to access that component.
Actually, all listed languages declare interoperability with Java, but not with other languages. So first design goal is, your platform should be Java-compatible in all its API, though some components could be written in other languages - but so that it is cannot be seen by API users. The easiest way to make it so is to write all in Java. Besides, I recommend Java because features of "more advanced" languages has their reverse side - one innocent-looking line of code can consume enormous amounts of CPU time or memory.
What I'm looking for is a scripting engine for Java that would allow users to write simple scripts to control the behavior and events for a game. Something that:
is simple - something easy to pick up, especially for people with some basic programming/scripting experience
provides lots of control - I can easily start/stop/pause scripts and control how much execution time each gets, perhaps how much memory space they can use
is separated from the Java environment itself - No access from scripts to any Java objects or classes, only to those functions I explicitly provide
I've considered the Rhino JavaScript engine, and it would suit my purposes, but from what I've read (example), it's designed to integrate with Java so much that sandboxing it securely would be tricky. I'd rather start with an engine that gives scripts no access to anything by default, than have a fully open one that I have to close up. The scripts might not always be trusted, so the environment should not be easy to break out of.
I'd also consider developing my own language with something like ANTLR, but it's probably more effort than I want to put in.
Any suggestions?
Have you considered Lua?
Google docs preview of a pdf on the subject
Lyrio, G.H.S.O; Seixas, R.B.; Using Lua as Script Language in Games Coded in Java, Proceedings of The North American Simulation and AI in Games Conference - GAMEON-NA, EUROSIS, Montreal, Canada, 2008.
You should give a try to Groovy, a scripting language that easily integrates with the Java platform.
Its syntax is 100% compatible with Java, but it also has a simplified syntax that makes it a suitable language for DSLs implementation.
I don't know for sure if you can stop/pause the execution of Groovy code from a Java program, you should read the Groovy API.
When executing Groovy code from within a Java program, you can specify the context passed to the script and you can query the context modified by the script for output variables. The script can be completely isolated from the underlying Java environment by creating a GroovyShell with an appropriate CompilerConfiguration.
JACL is one such language. It is based on TCL. Whatever you do, don't invent another language. There are plenty of good choices out there.
In my opinion not only language, but way of interfacing is important. JSR 223 is most compatible between different languages, but "native" seems the best (i.e. full object integration of groovy)