Netlogo controlador Api - Obtener vista de tabla

Fray:

Estoy usando Netlogo controlador de API con muelle de arranque esta mi código (lo tengo de este enlace )

HeadlessWorkspace workspace = HeadlessWorkspace.newInstance();
        try {
             workspace.open("models/Residential_Solar_PV_Adoption.nlogo",true);

             workspace.command("set number-of-residences 900");
             workspace.command("set %-similar-wanted 7");
             workspace.command("set count-years-simulated 14");
             workspace.command("set number-of-residences 500");
             workspace.command("set carbon-tax 13.7");
             workspace.command("setup");
             workspace.command("repeat 10 [ go ]");
             workspace.command("reset-ticks");
             workspace.dispose();

             workspace.dispose();
        }
        catch(Exception ex) {
                  ex.printStackTrace();
        }

me dieron este resultado en la consola:

introducir descripción de la imagen aquí

Pero quiero conseguir la vista de tabla y guardar en la base de datos. ¿Qué comando puedo utilizar para obtener la vista de tabla?

Vista de tabla:

introducir descripción de la imagen aquí

cualquier ayuda por favor?

Jasper:

Si usted puede aclarar por qué usted está tratando de generar los datos de esta manera, yo u otros podría ser capaz de dar un mejor asesoramiento.

No hay un único comando NetLogo o método API NetLogo para generar esa mesa, usted tiene que utilizar BehaviorSpace conseguirlo. Aquí están algunas opciones, en orden aproximado de más simple hasta el más duro.

Opción 1

If possible, I'd recommend just running BehaviorSpace experiments from the command line to generate your table. This will get you exactly the same output you're looking for. You can find information on how to do that in the NetLogo manual's BehaviorSpace guide. If necessary, you can run NetLogo headless from the command line from within a Java program, just look for resources on calling out to external programs from Java, maybe with ProcessBuilder.

If you're running from within Java in order to setup and change the parameters of your BehaviorSpace experiments in a way that you cannot do from within the program, you could instead generate experiment XML files in Java to pass to NetLogo at the command line. See the docs on the XML format.

Option 2

You can recreate the contents of the table using the CSV extension in your model and adding a few more commands to generate the data. This will not create the exact same table, but it will get your data output in a computer and human readable format.

In pure NetLogo code, you'd want something like the below. Note that you can control more of the behavior (like file names or the desired variables) by running other pre-experiment commands before running setup or go in your Java code. You could also run the CSV-specific file code from Java using the controlling API and leave the model unchanged, but you'll need to write your own NetLogo code version of the csv:to-row primitive.

globals [
  ;; your model globals here

  output-variables
]

to setup
  clear-all

  ;;; your model setup code here

  file-open "my-output.csv"
  ; the given variables should be valid reporters for the NetLogo model
  set output-variables [ "ticks" "current-price" "number-of-residences" "count-years-simulated" "solar-PV-cost" "%-lows" "k" ]
  file-print csv:to-row output-variables

  reset-ticks
end

to go
  ;;; the rest of your model code here

  file-print csv:to-row map [ v -> runresult v ] output-variables
  file-flush
  tick
end

Option 3

If you really need to reproduce the BehaviorSpace table export exactly, you can try to run a BehaviorSpace experiment directly from Java. The table is generated by this code but as you can see it's tied in with the LabProtocol class, meaning you'll have to setup and run your model through BehaviorSpace instead of just step-by-step using a workspace as you've done in your sample code.

Un buen ejemplo de esto podría ser el Main.scalaobjeto , que extrae algunos configuración de la prueba de los argumentos de línea de comandos que se espera, y luego los utiliza con el lab.run()método para ejecutar el experimento BehaviorSpace y generar la salida. Eso es código Scala y no Java, pero espero que no es demasiado difícil de traducir. Usted mismo modo tendría que configurar una org.nlogo.nvm.LabInterface.Settingsinstancia y pasas que fuera a una HeadlessWorkspace.newLab.run()para que funcione.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=313140&siteId=1
Recomendado
Clasificación