gsdlab / ClaferChocoIG

Project discontinued. Code merged into chocosolver project.
MIT License
0 stars 0 forks source link

ClaferChocoIG 0.3.9 does not work on person example from claferIDE #6

Closed toeklk closed 9 years ago

toeklk commented 9 years ago

Platform: mac os x yosemite

[kgad@lt00583 ~/Workspaces/varies/be.fmtc.costOptimization/Model]$  
 java -jar ~/install/clafer/claferchocoig.jar --repl --prettify --maxint=127 --scope=1 --file ~/git/gsdlab/claferIDE/Server/Examples/person.cfr 
Clafer Choco Instance Generator and Multi-Objective Optimizer
Compiling the Clafer model...
Unhandled compilation error occured. Please report this problem.
ReferenceError: "c0_TwoPersonLine" is not defined. (person.js#64)
mantkiew commented 9 years ago

That is a strange bug. TwoPersonLine is an abstract clafer, which is not extended. It is defined in the .js model:

scope({c0_TwoPersonLine:0});

c0_TwoPersonLine = Abstract("c0_TwoPersonLine").extending(c0_WaitingLine);

c0_TwoPersonLine.addConstraint(equal(card(join($this(), c0_participants)), constant(2)));

The last line is where the error is reported. Very strange, since c0_TwoPersonLine is defined. Could it be that it was somehow eliminated due to the scope of 0?

The compiler generates scope 0 for abstract clafers which are not extended by any concrete ones. This prevents Alloy from generating any instances of an abstract clafer.

JLiangWaterloo commented 9 years ago

The scope is actually just a Javascript map from string->double because that's how Javascript works. It isn't actually a reference so that's not the source of the reference error.

JLiangWaterloo commented 9 years ago

Additionally, this is an error from the Javascript interpretter. I don't resolve the scopes until after the interpretter is finished.

mantkiew commented 9 years ago

Ah, when I speak of compiler, I mean on the Haskell side. It generates scope 0 for unused abstract clafers. This gets embedded into the .js output. Yes, it seems it is a problem with the javascript interpreter on chocosolver's side.

JLiangWaterloo commented 9 years ago

For my lazy convenience, can someone copy+paste the js file?

mantkiew commented 9 years ago

It's the model Person from Clafer Tutorial example from

http://t3-necsis.cs.uwaterloo.ca:8194/

However, in my initial reply, I extracted the relevant lines from .js file.

scope({c0_Address:2, c0_City:2, c0_Country:2, c0_DateOfBirth:2, c0_Divorced:2, c0_Female:2, c0_Gender:2, c0_Male:2, c0_MaritalStatus:2, c0_Married:2, c0_Name:2, c0_NeverMarried:2, c0_NorthAmericanCountry:3, c0_OneToTenPersonLine:0, c0_Person:2, c0_PostalCode:2, c0_Street:2, c0_Surname:2, c0_TwoPersonLine:0, c0_UnitNo:2, c0_WaitingLine:4, c0_date:2, c0_participants:8});
defaultScope(1);
intRange(-8, 7);
stringLength(16);

c0_Person = Abstract("c0_Person");
c0_date = Abstract("c0_date");
c0_WaitingLine = Abstract("c0_WaitingLine");
c0_NorthAmericanCountry = Abstract("c0_NorthAmericanCountry");
c0_Person2 = Abstract("c0_Person2");
c0_Student = Abstract("c0_Student").extending(c0_Person);
c0_TwoPersonLine = Abstract("c0_TwoPersonLine").extending(c0_WaitingLine);
c0_OneToTenPersonLine = Abstract("c0_OneToTenPersonLine").extending(c0_WaitingLine);
c0_Name = c0_Person.addChild("c0_Name").withCard(1, 1);
c0_Surname = c0_Person.addChild("c0_Surname").withCard(1, 1);
c0_DateOfBirth = c0_Person.addChild("c0_DateOfBirth").withCard(1, 1).extending(c0_date);
c0_Gender = c0_Person.addChild("c0_Gender").withCard(1, 1).withGroupCard(1);
c0_Male = c0_Gender.addChild("c0_Male").withCard(0, 1);
c0_Female = c0_Gender.addChild("c0_Female").withCard(0, 1);
c0_MaritalStatus = c0_Person.addChild("c0_MaritalStatus").withCard(1, 1).withGroupCard(1, 1);
c0_NeverMarried = c0_MaritalStatus.addChild("c0_NeverMarried").withCard(0, 1);
c0_Married = c0_MaritalStatus.addChild("c0_Married").withCard(0, 1);
c0_Divorced = c0_MaritalStatus.addChild("c0_Divorced").withCard(0, 1);
c0_Address = c0_Person.addChild("c0_Address").withCard(1, 1);
c0_Street = c0_Address.addChild("c0_Street").withCard(1, 1);
c0_UnitNo = c0_Street.addChild("c0_UnitNo").withCard(0, 1);
c0_City = c0_Address.addChild("c0_City").withCard(1, 1);
c0_Country = c0_Address.addChild("c0_Country").withCard(1, 1);
c0_PostalCode = c0_Address.addChild("c0_PostalCode").withCard(1, 1);
c0_JohnDoe = Clafer("c0_JohnDoe").withCard(1, 1).extending(c0_Person);
c0_StudentId = c0_Student.addChild("c0_StudentId").withCard(1, 1);
c0_participants = c0_WaitingLine.addChild("c0_participants");
c0_MaryJane = Clafer("c0_MaryJane").withCard(1, 1).extending(c0_Student);
c0_BusLine = Clafer("c0_BusLine").withCard(1, 1).extending(c0_WaitingLine);
c0_JohnAndMaryLine = Clafer("c0_JohnAndMaryLine").withCard(1, 1).extending(c0_WaitingLine);
c0_Canada = Clafer("c0_Canada").withCard(1, 1).extending(c0_NorthAmericanCountry);
c0_USA = Clafer("c0_USA").withCard(1, 1).extending(c0_NorthAmericanCountry);
c0_Mexico = Clafer("c0_Mexico").withCard(1, 1).extending(c0_NorthAmericanCountry);
c1_Country = c0_Person2.addChild("c1_Country").withCard(1, 1);
c0_JohnDoe2 = Clafer("c0_JohnDoe2").withCard(1, 1).extending(c0_Person2);
c0_Name.refTo(string);
c0_Surname.refTo(string);
c0_Street.refTo(string);
c0_UnitNo.refTo(string);
c0_City.refTo(string);
c0_Country.refTo(string);
c0_PostalCode.refTo(string);
c0_date.refTo(string);
c0_StudentId.refTo(string);
c0_participants.refToUnique(c0_Person);
c1_Country.refTo(c0_NorthAmericanCountry);
c0_JohnDoe.addConstraint(equal(joinRef(join($this(), c0_Name)), constant("\"John\"")));
c0_JohnDoe.addConstraint(equal(joinRef(join($this(), c0_Surname)), constant("\"Doe\"")));
c0_JohnDoe.addConstraint(equal(joinRef(join($this(), c0_DateOfBirth)), constant("\"01-02-1985\"")));
c0_JohnDoe.addConstraint(some(join(join($this(), c0_Gender), c0_Male)));
c0_JohnDoe.addConstraint(some(join(join($this(), c0_MaritalStatus), c0_Married)));
c0_JohnDoe.addConstraint(equal(joinRef(join(join($this(), c0_Address), c0_Street)), constant("\"123 Main St.\"")));
c0_JohnDoe.addConstraint(equal(joinRef(join(join($this(), c0_Address), c0_City)), constant("\"Great Town\"")));
c0_JohnDoe.addConstraint(equal(joinRef(join(join($this(), c0_Address), c0_Country)), constant("\"Canada\"")));
c0_JohnDoe.addConstraint(equal(joinRef(join(join($this(), c0_Address), c0_PostalCode)), constant("\"A1B 2C3\"")));
c0_MaryJane.addConstraint(equal(joinRef(join($this(), c0_Name)), constant("\"Mary Jane\"")));
c0_MaryJane.addConstraint(equal(joinRef(join($this(), c0_StudentId)), constant("\"MJ13421354\"")));
c0_BusLine.addConstraint($in(global(c0_JohnDoe), joinRef(join($this(), c0_participants))));
c0_BusLine.addConstraint($in(global(c0_MaryJane), joinRef(join($this(), c0_participants))));
c0_JohnAndMaryLine.addConstraint(equal(joinRef(join($this(), c0_participants)), union(global(c0_JohnDoe), global(c0_MaryJane))));
c0_TwoPersonLine.addConstraint(equal(card(join($this(), c0_participants)), constant(2)));
c0_OneToTenPersonLine.addConstraint(greaterThanEqual(card(join($this(), c0_participants)), constant(1)));
c0_OneToTenPersonLine.addConstraint(lessThanEqual(card(join($this(), c0_participants)), constant(10)));
c0_JohnDoe2.addConstraint(equal(joinRef(join($this(), c1_Country)), global(c0_Canada)));
JLiangWaterloo commented 9 years ago

I can't seem to reproduce the error, neither locally on my machine nor with http://t3-necsis.cs.uwaterloo.ca:8194/

JLiangWaterloo commented 9 years ago

I think it might have something to do with "keep unused abstract clafer" flag from the Clafer compiler. There's no concrete Clafer extending TwoPersonLine.

mantkiew commented 9 years ago

@toeklk could you please download the latest binary and check this? Because we cannot reproduce, I am closing it.

toeklk commented 9 years ago

Hi,

I can still reproduce it, both using the latest source code from git, and the binary distribution for mac os x

[kgad@Klaass-MacBook-Air ~/Downloads/clafer-tools-0.3.9]$  
 java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
[kgad@Klaass-MacBook-Air ~/Downloads/clafer-tools-0.3.9]$  
  java -jar ~/Downloads/clafer-tools-0.3.9/claferchocoig.jar --repl --prettify --maxint=127 --scope=1 --file ~/git/gsdlab/claferIDE/Server/Examples/person.cfr 
Clafer Choco Instance Generator and Multi-Objective Optimizer
Compiling the Clafer model...
Unhandled compilation error occured. Please report this problem.
ReferenceError: "c0_TwoPersonLine" is not defined. (person.js#64)

However, I must say that, since the last commits on master, claferchocoIG is a lot more stable/functional on my own applications!