On the crisis

It was interesting to find in a classic (Hobsbawm’s Age of Extremes, 1994) the prophecy on the failures of economic theory to deal with crises:

As unemployment soared, it did not seem plausible … that public works would not increase employment at all, because the money spent on them would merely be diverted from the private sector, which would otherwise have generated just as much employment.

Economists who simply advised leaving the economy alone, governments whose first instincts, apart from protecting the gold standard by deflationary policies, was to stick to financial orthodoxy, balance budgets and cut costs, were visibly not making the situation better.

…us who lived through the years of the Great Slump still find it almost impossible to understand how the orthodoxies of the pure free market, then so obviously discredited once again came to preside over a global period of depression in the late 1980s and 1990s, which, once again, they were equally unable to understand or to deal with.

Another case where I came to think that we don’t really need a simulation to understand.

Reading one year of JASSS (2013)

To answer a comment by a reviewer, I decided to read (well, browse) a whole year of JASSS papers and to mark down which of them contained constructs that correspond to mental representations and which ones didn’t. As I went reading, it was obvious that my simple grid wasn’t very good; that in some cases, it’s hard to tell if you have only “simple” agents – that is, agents following the KISS principle – or not. At the same time, I got immediately greedy: I started to collect more data in the grid – some of them when I had already moved forward, and I didn’t feel like going back to fill the previous slots.

I don’t know if this can be of any use but to myself – but here it is just in case. Note that I’m publishing it as an editable google spreadsheet, so if you feel I made some mistake, you can just go and correct them.

The editable spreadsheet (if I have made no uploading mistakes) is here

How to quickly run a Jason project

How to open an existing project in the default iEdit Jason environment?

For those of you that don’t want to start Eclipse every time you need to test a Jason project (as an example, located in ./Donwloads/TestProject), the mechanism is

  1. open jEdit
  2. go to menu plugins – Jason – new project
  3. select as root location the directory immediately ABOVE the one you’re looking for (in the example, ./Downloads)
  4. put as project name the exact name of the directory, not the name of the .mas2j file that might be different (in the example, TestProject)
  5. if the name of the .mas2j file is NOT same as the project, the editor will propose an empty .mas2j file. Close it without saving, remove it from the directory, and proceed to open the real .mas2j file.

You’re all set.

Running Jason by command line

Simple enough it should be somethihg like:

java -Xms2000M -Xmx2000M -XX:NewSize=1500M 
  -XX:UseParallelGC 
  -classpath './lib/jason.jar:./lib/c4jason.jar:./lib/cartago.jar:./bin/classes' 
  jason.infra.centralised.RunCentralisedMAS ModelName.mas2j

Test it – of course, this line assumes that the directory structure is such that the instruction is issued in the main Jason directory (so the ./lib/jason.jar works) and that the classes are placed in .bin/classes.

Notes on Jason

In this post, I will list some ideas I got about Jason from the Simulation module in the course at the university of Bologna. Specifically, I will focus on these ways of writing agentspeak code that is correct but looks not natural to those who are knowedgable (for me, it’s good ‘ole Fran who first helped me to the exoteric aspects of this way of thinking.

So, without further ado, let’s list some classic “mistakes.” We start from code written from two excellent students. We have a list of [value, key], for example, [[1,a][2,b][3,c]] and a list of names, [ a,c, d]. We want to keep items in the first list only if they have the name in second. The result must be sorted.

Solution 1:

!updateList([[1,a][2,b][3,c]], [a,c,d], []).

+!updateList(Couples, Names, Res) <-
	.length(Couples, CouplesLength);
	//CouplesLength = CouplesLength; // ??
	if (CouplesLength > 0) {
		.nth(0, Couples, CurrentCouple)
		.delete(0, Couples, TailCouples);
		.nth(1, CurrentCouple, CurrentName); 
		if (.member(CurrentName, Names)) {
			.concat([CurrentCouple], Res, NewRes);
			!updateList(TailCouples, Names, NewRes);
		} else {
			// do nothing, thus losing the current couple.
			!updateList(TailCouples, Names, Res);
		}
	}
	else {
		// ultima esecuzione del piano per il ciclo in corso
		.sort(Res, SortedRes);
		.print(SortedRes);
	}
	.

This solution works – but * it doesn’t use the context, instead it uses nested if as if we were in java; * it doesn’t process the list in the logical [H|T] way; * accesses elements inside a list with .nth instead of just unifying them.

A solution that does the same but only using logical style programming is the following:

!updateList([[1,a][2,b][3,c]], [a,c,d], []).

// update the ones I know.
+!updateList([[Value, Name]| T], Names, Res): .member(Name, Names) <-
	.concat([[Value, Name]], Res, NewRes);
	!updateList(T, Names, NewRes).

// drop the ones I don't know.
+!updateWages([[Value, Name]| T], Names, Res) <-
	!updateList(T, Old, Res).

// wrap it up	
+!updateWages([], Names, Res) <-
		.sort(Res, SortedRes);
		.print(SortedRes).

Which one is more readable? Which one is easiest to maintain?

← Older Newer →