Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Maven CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Set up Maven
uses: stCarolas/setup-maven@v4.5
with:
maven-version: 3.8.2
- name: Build with Maven
run: mvn -B package --file pom.xml

16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://secure.travis-ci.org/gsdlab/chocosolver.svg)](http://travis-ci.org/gsdlab/chocosolver)
[![Build Status](https://github.com/EthanJamesLew/chocosolver-sysml/actions/workflows/maven.yml/badge.svg)](https://github.com/EthanJamesLew/chocosolver-sysml/actions/workflows/maven.yml)

# chocosolver

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/clafer/ast/analysis/PartialIntAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ private Map<AstConcreteClafer, Domain[]> partialInts(Oracle oracle) {
AstRef ref = AstUtil.getInheritedRef(clafer);
if (ref != null) {
Path[][] paths = pathsToClafers.get(clafer);
// NULL_DEREFERENCE
if (paths == null){
return partialInts;
}
Domain[] domains = new Domain[paths.length];
for (int i = 0; i < paths.length; i++) {
Domain domain = Domains.EmptyDomain;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/clafer/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void main(String[] args) throws Exception {
accepts( "noprint", "Don't print the instances to the console or a file");
accepts( "output", "Output instances to the given file." ).withRequiredArg().ofType( File.class ).describedAs( "text file" );
accepts( "prettify", "Use simple and pretty output format (not formal)." );
accepts( "sysml", "Print the instances as SysMLv2" );
accepts( "repl", "Run in REPL (interactive) mode." );
accepts( "scope", "Override the default global scope value." ).withRequiredArg().ofType( Integer.class );
accepts( "search", "PreferSmallerInstances/PreferLargerInstances/Random" ).withRequiredArg().ofType( ClaferSearchStrategy.class );
Expand Down
63 changes: 43 additions & 20 deletions src/main/java/org/clafer/cli/Normal.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import org.clafer.javascript.JavascriptFile;
import org.clafer.objective.Objective;
import org.clafer.scope.Scope;
import org.clafer.ast.AstModel;
import org.sysml.ast.SysmlProperty;
import org.sysml.ast.SysmlPropertyDef;
import org.sysml.compiler.AstSysmlCompiler;
import org.sysml.pprinter.SysmlPrinter;


public class Normal {
Expand Down Expand Up @@ -39,6 +44,7 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options,

int index = 0; // instance id
boolean prettify = options.has("prettify");
boolean sysml = options.has("sysml");
boolean printOff = options.has("noprint");
boolean dataTackingOn = options.has("dataFile");
boolean timeOn = options.has("time");
Expand Down Expand Up @@ -71,28 +77,45 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options,
if (printOff) {
++index;
} else {
outStream.println("=== Instance " + (++index) + " Begin ===\n");
InstanceModel instance = solver.instance();
if (prettify)
instance.print(outStream);
else
for (InstanceClafer c : instance.getTopClafers())
Utils.printClafer(c, outStream);
outStream.println("\n--- Instance " + (index) + " End ---\n");
if (sysml) {
outStream.append("package Architecture {\n");
outStream.append(" import ScalarValues::*;\n");
AstModel top = javascriptFile.getModel();
SysmlPrinter pprinter = new SysmlPrinter(outStream);
AstSysmlCompiler compiler = new AstSysmlCompiler();
SysmlPropertyDef[] models = compiler.compile(top, top);
for (SysmlPropertyDef model: models){
pprinter.visit(model, " ");
}

InstanceModel instance = solver.instance();
instance.printSysml(outStream, " ");
outStream.append("}\n");
} else {
outStream.println("=== Instance " + (++index) + " Begin ===\n");
InstanceModel instance = solver.instance();
if (prettify)
instance.print(outStream);
else
for (InstanceClafer c : instance.getTopClafers())
Utils.printClafer(c, outStream);
outStream.println("\n--- Instance " + (index) + " End ---\n");
}
}
}
if (timeOn) {
elapsedTime = (double) (System.nanoTime() - startTime) / 1000000000;
if (objectives.length == 0)
System.out.println("Generated " + index + " instance(s) within the scope in " + elapsedTime + " seconds\n");
else
System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope in " + elapsedTime + " secondse\n");
} else {
if (objectives.length == 0)
System.out.println("Generated " + index + " instance(s) within the scope\n");
else
System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope\n");
if (!sysml) {
if (timeOn) {
elapsedTime = (double) (System.nanoTime() - startTime) / 1000000000;
if (objectives.length == 0)
System.out.println("Generated " + index + " instance(s) within the scope in " + elapsedTime + " seconds\n");
else
System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope in " + elapsedTime + " secondse\n");
} else {
if (objectives.length == 0)
System.out.println("Generated " + index + " instance(s) within the scope\n");
else
System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope\n");
}
}

}
}
26 changes: 26 additions & 0 deletions src/main/java/org/clafer/instance/InstanceModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.clafer.ast.AstConcreteClafer;
import org.clafer.common.Check;
import org.sysml.ast.SysmlProperty;
import org.sysml.compiler.InstanceSysmlCompiler;
import org.sysml.pprinter.SysmlPrinter;

/**
*
Expand Down Expand Up @@ -49,6 +53,28 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) {
return typedTopClafer;
}

/**
* Print solution as SysMLv2
*
* This is the start of exploring an automated product derivation tool
* and the requirements around inferring a system model from clafer are
* still tbd
*
*
*/
public void printSysml(Appendable out, String indent) throws IOException {


for (InstanceClafer top : topClafers) {
SysmlPrinter pprinter = new SysmlPrinter(out);
InstanceSysmlCompiler compiler = new InstanceSysmlCompiler();
// model can be null as the clafer model might not reference sysml concepts
Object _model = compiler.compile(top, top);
if (_model != null)
pprinter.visit((SysmlProperty) _model, indent);
}
}

/**
* Print solution to stdout.
*
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/sysml/ast/SysmlAttribute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.sysml.ast;

import java.io.IOException;

public class SysmlAttribute implements SysmlExpr, SysmlId {
private String name;

private Object ref;

public SysmlAttribute(String name, Object ref) {
this.name = name;
this.ref = ref;
}

@Override
public String getName() {
return name;
}

public String getRef() {
return ref.toString();
}
@Override
public <A, B> B accept(SysmlExprVisitor<A, B> visitor, A a) throws IOException {
return visitor.visit(this, a);
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/sysml/ast/SysmlBlockDefElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.sysml.ast;

public interface SysmlBlockDefElement extends SysmlExpr, SysmlId {
}
14 changes: 14 additions & 0 deletions src/main/java/org/sysml/ast/SysmlBlockVisibility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sysml.ast;

/**
* Sysml Block Visibility
* <block-visibility> ::=<namespace-visibility> | ‘#’ | ‘~’
*/
public class SysmlBlockVisibility {
public final SysmlVisibilityOption option;

public SysmlBlockVisibility(SysmlVisibilityOption visOpt) {
this.option = visOpt;
}

}
16 changes: 16 additions & 0 deletions src/main/java/org/sysml/ast/SysmlExpr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sysml.ast;

import java.io.IOException;

public interface SysmlExpr {
/**
* Dynamic dispatch on the visitor.
*
* @param <A> the parameter type
* @param <B> the return type
* @param visitor the visitor
* @param a the parameter
* @return the return value
*/
<A, B> B accept(SysmlExprVisitor<A, B> visitor, A a) throws IOException;
}
13 changes: 13 additions & 0 deletions src/main/java/org/sysml/ast/SysmlExprVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.sysml.ast;

import java.io.IOException;

public interface SysmlExprVisitor <A, B>{
B visit(SysmlPackage ast, A a) throws IOException;

B visit(SysmlProperty ast, A a) throws IOException;

B visit(SysmlAttribute ast, A a) throws IOException;

B visit(SysmlPropertyDef sysmlPropertyDef, A a) throws IOException;
}
10 changes: 10 additions & 0 deletions src/main/java/org/sysml/ast/SysmlId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sysml.ast;

public interface SysmlId {
/**
* SysML <language-identifier>
*
* @return the name of the identifier
*/
String getName();
}
31 changes: 31 additions & 0 deletions src/main/java/org/sysml/ast/SysmlPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.sysml.ast;



import java.io.IOException;

/**
* TODO: build out the DiagramElement taxonomy better
*/
public class SysmlPackage implements SysmlBlockDefElement {
private final SysmlBlockDefElement[] elements;
private final String name;

public SysmlPackage(String name, SysmlBlockDefElement[] elements){
this.elements = elements;
this.name = name;
}

public String getName() {
return name;
}

public SysmlBlockDefElement[] getElements(){
return elements;
}

@Override
public <A, B> B accept(SysmlExprVisitor<A, B> visitor, A a) throws IOException {
return visitor.visit(this, a);
}
}
Loading