diff --git a/src/cp/Terms.scala b/src/cp/Terms.scala index 5faf87ddb6990143abeed20c992a3fbb5a9184cf..de3705788e1bc72e2d8cacfc1db5a15de8445ac0 100644 --- a/src/cp/Terms.scala +++ b/src/cp/Terms.scala @@ -35,6 +35,28 @@ object Terms { } } + /** This construct represents a constraint with an expression to minimize */ + abstract class MinConstraint[T](cons : Constraint[_], minFunc : IntTerm[_]) { + val convertingFunction : (Seq[Expr] => T) + + def solve : T = { + convertingFunction(solveMinimizingExprSeq(cons, minFunc)) + } + + def find : Option[T] = { + try { + Some(this.solve) + } catch { + case e: UnsatisfiableConstraintException => None + case e: UnknownConstraintException => None + } + } + + def findAll : Iterator[T] = { + findAllMinimizingExprSeq(cons, minFunc).map(convertingFunction(_)) + } + } + /** Contains helper methods for constructing base terms */ object Term { def processArgs(converter : Converter, serializedProg : Serialized, serializedInputVars : Serialized, serializedOutputVars : Serialized, serializedExpr : Serialized, inputVarValues : Seq[Expr]) : (Converter,Program,Expr,Seq[TypeTree]) = { @@ -68,7 +90,7 @@ object Terms { } */ - /** A constraint is just a term with Boolean range */ + /** Type aliases for terms with boolean and integer range */ type Constraint[T] = Term[T,Boolean] type Constraint1[T1] = Term1[T1,Boolean] type Constraint2[T1,T2] = Term2[T1,T2,Boolean] @@ -79,6 +101,7 @@ object Terms { type Constraint7[T1,T2,T3,T4,T5,T6,T7] = Term7[T1,T2,T3,T4,T5,T6,T7,Boolean] type Constraint8[T1,T2,T3,T4,T5,T6,T7,T8] = Term8[T1,T2,T3,T4,T5,T6,T7,T8,Boolean] type Constraint9[T1,T2,T3,T4,T5,T6,T7,T8,T9] = Term9[T1,T2,T3,T4,T5,T6,T7,T8,T9,Boolean] + type IntTerm[T] = Term[T,Int] type IntTerm1[T1] = Term1[T1,Int] type IntTerm2[T1,T2] = Term2[T1,T2,Int] @@ -650,27 +673,6 @@ object Terms { case Term(p,ex,ts,conv) => Term9(p,Not(ex),ts,conv) } } - /** This construct represents a constraint with an expression to minimize */ - abstract class MinConstraint[T](cons : Constraint[_], minFunc : IntTerm[_]) { - val convertingFunction : (Seq[Expr] => T) - - def solve : T = { - convertingFunction(solveMinimizingExprSeq(cons, minFunc)) - } - - def find : Option[T] = { - try { - Some(this.solve) - } catch { - case e: UnsatisfiableConstraintException => None - case e: UnknownConstraintException => None - } - } - - def findAll : Iterator[T] = { - findAllMinimizingExprSeq(cons, minFunc).map(convertingFunction(_)) - } - } case class MinConstraint1[T1](cons : Term1[T1,Boolean], minFunc : Term1[T1,Int]) extends MinConstraint[(T1)](cons, minFunc) { val convertingFunction = converterOf(cons).exprSeq2scala1[T1] _ diff --git a/src/cp/Utils.scala b/src/cp/Utils.scala index 335cc062e9739112d3a6c5fdec44bbeba665de75..3f6df67db93d194c1eed56444d0f269b586a3bb1 100644 --- a/src/cp/Utils.scala +++ b/src/cp/Utils.scala @@ -47,8 +47,12 @@ object Utils { } } }).flatten.flatten - - methods.mkString("\n\n") + val comments = +"""/********** TERM METHODS **********/ +/** compose_i_j_k will compose f (of arity j) and g (of arity k) as "g∘f" by + * inserting arguments of f in place of argument i of g */ +""" + comments + methods.mkString("\n\n") } } @@ -190,7 +194,8 @@ object Utils { intTerms = intType :: intTerms } - (booleanTerms.reverse ++ intTerms.reverse).mkString("\n") + val comment = """/** Type aliases for terms with boolean and integer range */""" + (Seq(comment) ++ booleanTerms.reverse ++ intTerms.reverse).mkString("\n") } } @@ -213,11 +218,15 @@ object Utils { } def main(args: Array[String]) : Unit = { - println(GenerateCompose(args(0).toInt)) - println(GenerateTerms(args(0).toInt)) - println(GenerateTermObjects(args(0).toInt)) - println(GenerateMinConstraintClasses(args(0).toInt)) - println(GenerateTypeAliases(args(0).toInt)) - println(GenerateConverterMethods(args(0).toInt)) + val staticComposeMethods = GenerateCompose(args(0).toInt) + val termTraits = GenerateTerms(args(0).toInt) + val termObjects = GenerateTermObjects(args(0).toInt) + val minConstraintsClasses = GenerateMinConstraintClasses(args(0).toInt) + val typeAliases = GenerateTypeAliases(args(0).toInt) + + val converterMethods = GenerateConverterMethods(args(0).toInt) + + val everything = Seq(typeAliases, termTraits, termObjects, minConstraintsClasses, staticComposeMethods).mkString("\n\n") + println(indent(everything)) } }