# The classowary Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

# The classowary Reference Manual

This is the classowary Reference Manual, version 1.0.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Sun May 15 04:21:07 2022 GMT+0.

Next: , Previous: , Up: Top   [Contents][Index]

## 1 Introduction

```## About Classowary
Classowary is an implementation of the linear constraint solver toolkit "Cassowary"(https://overconstrained.io). It is a variant of the simplex solver algorithm, specifically designed to allow adding, removing, and updating constraints quickly. This makes it a good candidate for layout computations.

## How To
After loading Classowary you will likely want to create a local nickname in your package for ``org.shirakumo.classowary``. We will assume that this nickname is called ``cass`` for this tutorial.

:: common lisp
(defvar *solver* (cass:make-solver))

(cass:with-variables (a b c) *solver*
(cass:constrain *solver* (<= 0 a))
(cass:constrain *solver* (<= a 10))
(cass:constrain *solver* (= b (* (+ 1 a) 5)))
(cass:constrain *solver* (= (+ 3 (* 2 c)) (+ a b)))
(cass:update-variables *solver*)
(values (cass:value a) (cass:value b) (cass:value c)))
;; => 0 5 1
::

As you can see, the solver picked only one of many possible solutions. When the system is underconstrained, it isn't predictable which solution you will get, but it should always fulfil all constraints that were given. If the system is overconstrained, Cassowary will try to match them as closely as possible according to each constraint's strength.

Cassowary also allows you to "suggest" a value for a variable. This means that the solver will try to keep the variable to this value if possible.

:: common lisp
(cass:with-variables (a b c) *solver*
(cass:make-suggestable a)
(cass:suggest a 5)
(cass:update-variables *solver*)
(values (cass:value a) (cass:value b) (cass:value c)))
;; => 5 30 16
::

This is typically how you will want to impose additional constraints imposed by the user such as when they explicitly move or resize something.

Naturally you can impose additional constraints at a later point as well.

:: common lisp
(cass:with-variables (a b c) *solver*
(cass:constrain *solver* (<= a (/ c 4)) :name 'a)
(cass:update-variables *solver*)
(values (cass:value a) (cass:value b) (cass:value c)))
;; => 1 10 4
::

As you can see, with this additional constraint the solver was no longer able to fulfil our suggested value exactly. We can easily remove the offending constraint again.

:: common lisp
(cass:delete-constraint (cass:find-constraint 'a *solver*))
::

Instead of using the ``constrain`` and ``with-variables`` macros, you can also dynamically build the variables and constraints through ``make-variable``, ``make-constraint``, ``add-term``, ``relation``, and ``add-constraint``. When building constraints and variables, you should make sure to pass the ``:name`` argument so that you can retrieve them from the solver later, or keep references of your own somewhere.

Should a solver or constraint get into a bad state, you can attempt to clear their state out with ``reset-solver`` and ``reset-constraint`` respectively.

The Cassowary algorithm is described in the paper "The Cassowary Linear Arithmetic Constraint Solving Algorithm: Interface and Implementation" by Badros and Borning[1]. You can find the website of the original implementation "here"(https://constraints.cs.washington.edu/cassowary/).

This implementation is largely based on the "Amoeba implementation"(https://github.com/starwing/amoeba) by Xavier Wang.

[1]: https://constraints.cs.washington.edu/cassowary/cassowary-tr.pdf

```

Next: , Previous: , Up: Top   [Contents][Index]

## 2 Systems

The main system appears first, followed by any subsystem dependency.

Previous: , Up: Systems   [Contents][Index]

### 2.1 classowary

Maintainer

Nicolas Hafner <shinmera@tymoon.eu>

Author

Nicolas Hafner <shinmera@tymoon.eu>

zlib

Description

An implementation of the Cassowary linear constraint solver toolkit

Version

1.0.0

Dependency

documentation-utils

Source

classowary.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

## 3 Files

Files are sorted by type and then listed depth-first from the systems components trees.

Previous: , Up: Files   [Contents][Index]

### 3.1 Lisp

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.1 classowary.asd

Location

classowary.asd

Systems

classowary (system)

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.2 classowary/package.lisp

Parent

classowary (system)

Location

package.lisp

Packages

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.3 classowary/toolkit.lisp

Dependency

package.lisp (file)

Parent

classowary (system)

Location

toolkit.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.4 classowary/conditions.lisp

Dependency

toolkit.lisp (file)

Parent

classowary (system)

Location

conditions.lisp

Exported Definitions
Internal Definitions

when-ok (macro)

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.5 classowary/symbol.lisp

Dependency

conditions.lisp (file)

Parent

classowary (system)

Location

symbol.lisp

Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.6 classowary/expression.lisp

Dependency

symbol.lisp (file)

Parent

classowary (system)

Location

expression.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.7 classowary/constraint.lisp

Dependency

expression.lisp (file)

Parent

classowary (system)

Location

constraint.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.8 classowary/cassowary.lisp

Dependency

constraint.lisp (file)

Parent

classowary (system)

Location

cassowary.lisp

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.9 classowary/documentation.lisp

Dependency

cassowary.lisp (file)

Parent

classowary (system)

Location

documentation.lisp

Next: , Previous: , Up: Top   [Contents][Index]

## 4 Packages

Packages are listed by definition order.

Previous: , Up: Packages   [Contents][Index]

### 4.1 org.shirakumo.classowary

Source

package.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

## 5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.

Next: , Previous: , Up: Definitions   [Contents][Index]

### 5.1 Exported definitions

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.1 Constants

Constant: +medium+

Constant for constraints with a medium weight.

Corresponds to 1e3. You can also specify the keyword :medium instead of this constant wherever strengths are accepted.

Package
Source

toolkit.lisp (file)

Constant: +none+

Constant for constraints with no weight.

Corresponds to 0e0. You can also specify the keyword :none instead of this constant wherever strengths are accepted.

Package
Source

toolkit.lisp (file)

Constant: +required+

Constant for constraints with a very high weight.

Corresponds to 1e9. You can also specify the keyword :required instead of this constant wherever strengths are accepted.

Package
Source

toolkit.lisp (file)

Constant: +strong+

Constant for constraints with a high weight.

Corresponds to 1e6. You can also specify the keyword :strong instead of this constant wherever strengths are accepted.

Package
Source

toolkit.lisp (file)

Constant: +weak+

Constant for constraints with a weak weight.

Corresponds to 1e0. You can also specify the keyword :weak instead of this constant wherever strengths are accepted.

Package
Source

toolkit.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.2 Macros

Macro: constrain SOLVER CONSTRAINT &rest ARGS &key NAME STRENGTH

Constrain the linear system in the solver.

The constraint should be an expression of the following form:

CONSTRAINT ::= (RELATION EXPRESSION EXPRESSION)
RELATION ::= <= | = | >=
EXPRESSION ::= TERM | COMPOUND
COMPOUND ::= (+ EXPRESSION*)
| (- EXPRESSION+)
| (* EXPRESSION*)
| (/ EXPRESSION+)
TERM ::= variable | real | (quote quoted)
variable — A CL variable binding name.
quoted — A symbol naming a solver variable.
real — A real number.

If a quoted variable is used, the variable is retrieved from the solver, or created if it does not exist yet. It will have the name of the quoted symbol. Otherwise the variable denotes a CL variable whose value must be of type VARIABLE.

If the expression contains non-linear terms, such as the multiplication of two variables, or the division by a variable, an error is signalled at macro-expansion-time.

This macro is a short-hand to create constraint, add terms, set the relation, and add the constraint to the solver.

The new constraint instance is returned.

See CONSTRAINT (type)
See SOLVER (type)
See MAKE-CONSTRAINT
See RELATION

Package
Source

constraint.lisp (file)

Macro: with-variables VARS SOLVER &body BODY

Convenience macro to create and bind multiple variables at once.

Each binding must follow this structure:

BINDING ::= variable | (variable name? strength?)
variable — The CL variable the solver variable is bound to. name — The name of the solver variable as a symbol.
This can later be used to retrieve the variable. If no explicit name is given, the CL variable name is used. strength — The strength of the variable if it is newly created.

If a variable with the given name already exists in the solver, it is returned. Otherwise, a new variable of the given name is created. If NAME is NIL, a new variable is always created.

Note that the variables are /not/ deleted on exit from the body.

See VARIABLE (type)
See SOLVER (type)
See FIND-VARIABLE
See MAKE-VARIABLE

Package
Source

constraint.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.3 Compiler macros

Compiler Macro: add-term CONSTRAINT MULTIPLIER &optional VARIABLE
Package
Source

constraint.lisp (file)

Compiler Macro: remove-term CONSTRAINT MULTIPLIER &optional VARIABLE
Package
Source

constraint.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.4 Functions

Adds the constraint to its solver.

Without this, the constraint will not apply.

If the solver is AUTO-UPDATE, the variables will be updated after this operation.

See SOLVER
See CONSTRAINT (type)
See REMOVE-CONSTRAINT

Package
Source

cassowary.lisp (file)

Function: add-term CONSTRAINT MULTIPLIER &optional VARIABLE

Adds the given term description to the constraint.

This corresponds to a term of either
number
or
number*variable
being added to the constraint depending on whether the variable is given.

Note that adding or removing terms can automatically cancel out as soon as either the constant term of the expression reaches zero, or the multiplier of a variable term reaches zero. In the latter case, the variable term is automatically removed from the expression.

Returns the updated constraint.

See CONSTRAINT (type)
See VARIABLE (type)
See REMOVE-TERM

Package
Source

constraint.lisp (file)

Function: auto-update SOLVER

Accessor to whether the solver automatically updates variables on changes.

See SOLVER (type)

Package
Source

constraint.lisp (file)

Writer

(setf auto-update) (function)

Function: (setf auto-update) VALUE SOLVER
Package
Source

constraint.lisp (file)

auto-update (function)

Function: clone-constraint OTHER &key STRENGTH

Return a copy of the given constraint.

This will copy the constraint including its terms into a fresh instance.

See CONSTRAINT (type)
See MAKE-CONSTRAINT
See DELETE-CONSTRAINT

Package
Source

constraint.lisp (file)

Function: constrain-with SOLVER CONSTRAINT &key NAME STRENGTH

Constrain the linear system in the solver.

This is like CONSTRAIN, except that this is a function and can thus accept run-time expressions. Instead of variables being either literal symbols or quoted symbols, you can pass VARIABLE instances or symbols to achieve the equivalent effects.

The new constraint instance is returned.

See CONSTRAIN
See VARIABLE (type)

Package
Source

constraint.lisp (file)

Function: constrained-p CONSTRAINT

Returns true if the constraint is additionally constrained through a variable.

See CONSTRAINT (TYPE)

Package
Source

cassowary.lisp (file)

Function: delete-constraint CONSTRAINT

Deletes the constraint completely from the solver.

This will render the constraint useless. Operating on it beyond this point results in undefined behaviour.

See CONSTRAINT (type)
See MAKE-CONSTRAINT

Package
Source

constraint.lisp (file)

Function: delete-variable VARIABLE

Deletes the variable completely from the solver.

This will remove the variable and all terms in all expressions that include it.

See MAKE-VARIABLE
See VARIABLE (type)

Package
Source

constraint.lisp (file)

Function: find-constraint SYMBOL SOLVER

Returns the constraint associated with the given name, if any.

Note that you are /not/ permitted to SETF this place.

See CONSTRAINT (type)
See SOLVER (type)

Package
Source

constraint.lisp (file)

Writer

(setf find-constraint) (function)

Function: (setf find-constraint) CONSTRAINT SYMBOL SOLVER
Package
Source

constraint.lisp (file)

find-constraint (function)

Function: find-variable SYMBOL SOLVER

Returns the variable associated with the given name, if any.

Note that you are /not/ permitted to SETF this place.

See VARIABLE (type)
See SOLVER (type)

Package
Source

constraint.lisp (file)

Writer

(setf find-variable) (function)

Function: (setf find-variable) VARIABLE SYMBOL SOLVER
Package
Source

constraint.lisp (file)

find-variable (function)

Function: make-constraint SOLVER &key NAME STRENGTH

Returns a new constraint for the solver.

The STRENGTH designates how strongly this constraint is adhered. By default the strength is +REQUIRED+.

The NAME is an optional identifier for the constraint. The name may be a string or a symbol. If it is a symbol, the constraint can later be retrieved by the same symbol again, using FIND-CONSTRAINT.

See STRENGTH (type)
See DELETE-CONSTRAINT
See FIND-CONSTRAINT

Package
Source

constraint.lisp (file)

Function: make-solver &key AUTO-UPDATE

Returns a new solver instance.

If AUTO-UPDATE is T, the solver will automatically call UPDATE-VARIABLES when constraints or variables change.

See SOLVER (type)
See AUTO-UPDATE
See RESET-SOLVER
See MAKE-CONSTRAINT
See CONSTRAIN
See MAKE-VARIABLE
See WITH-VARIABLES

Package
Source

cassowary.lisp (file)

Function: make-suggestable VARIABLE &optional STRENGTH

Make the variable suggestable.

This means that you can edit the variable and suggest a value that the solver should try to keep steady when solving its system. Typically this is used for variables that are constrained by the user somehow.

In order to use SUGGEST, a variable must first be made suggestable.

If the variable is already suggestable, its strength is updated via (SETF STRENGTH).

If the variable was not already suggestable, it is suggested to the current value of the variable.

The strength of the suggestion is capped to +STRONG+. Any value above will automatically be reduced to +STRONG+.

Returns the variable.

See STRENGTH
See VARIABLE (type)
See MAKE-UNSUGGESTABLE
See SUGGESTABLE-P
See SUGGEST
See STRENGTH

Package
Source

cassowary.lisp (file)

Function: make-unsuggestable VARIABLE

Makes the variable unsuggestable again.

After this, SUGGEST will fail unless the variable is explicitly made suggestable again.

Returns the variable.

See MAKE-SUGGESTABLE
See SUGGESTABLE-P
See VARIABLE (type)
See SUGGEST

Package
Source

cassowary.lisp (file)

Function: make-variable SOLVER &key NAME STRENGTH

Returns a new variable for the solver.

The NAME is an optional identifier for the variable. The name may be a string or a symbol. If it is a symbol, the variable can later be retrieved by the same symbol again, using FIND-VARIABLE.

If STRENGTH is given, the variable is made suggestable and
its strength set accordingly. STRENGTH may also be T in this case, in which case the strength used is +STRONG+.

See VARIABLE (type)
See DELETE-VARIABLE
See MAKE-SUGGESTABLE
See FIND-VARIABLE

Package
Source

constraint.lisp (file)

Function: relation CONSTRAINT

Accessor to the relation of the constraint.

May be one of the following CL symbols:

<=
=
>=

See CONSTRAINT (type)

Package
Source

constraint.lisp (file)

Writer

(setf relation) (function)

Function: (setf relation) RELATION CONSTRAINT
Package
Source

constraint.lisp (file)

relation (function)

Function: remove-constraint CONSTRAINT

Removes the constraint from its solver.

After this, the constraint will not apply.

If the solver is AUTO-UPDATE, the variables will be updated after this operation.

See SOLVER
See CONSTRAINT (type)
See REMOVE-CONSTRAINT

Package
Source

cassowary.lisp (file)

Function: remove-term CONSTRAINT MULTIPLIER &optional VARIABLE

Removes the given term description from the constraint.

This corresponds to a term of either
number
or
number*variable
being removed from the constraint depending on whether the variable is given.

Note that adding or removing terms can automatically cancel out as soon as either the constant term of the expression reaches zero, or the multiplier of a variable term reaches zero. In the latter case, the variable term is automatically removed from the expression.

This operation is equivalent to ADD-TERM with the multiplier inverted.

Returns the updated constraint.

See CONSTRAINT (type)
See VARIABLE (type)

Package
Source

constraint.lisp (file)

Function: reset-constraint CONSTRAINT

Resets the constraint.

This will remove the constraint, unset its relation, and clear its expression of all terms.

Returns the updated constraint.

See CONSTRAINT (type)
See REMOVE-CONSTRAINT

Package
Source

constraint.lisp (file)

Function: reset-solver SOLVER &optional CLEAR-CONSTRAINTS

Resets the solver.

This resets all variables and makes them unsuggestable.

If the solver is AUTO-UPDATE, the variables will be updated before this operation.

If CLEAR-CONSTRAINTS is T, removes all constraints from the solver.

See SOLVER (type)

Package
Source

cassowary.lisp (file)

Function: strength CONSTRAINT

Accessor to the strength of the constraint.

The strength is a positive float, denoting how important this constraint is to the overall system. Valid values for the strength are positive real numbers and the following keywords:

:REQUIRED
:STRONG
:MEDIUM
:WEAK
:NONE

Each of these keywords corresponds to the constant of the same name. If a value that is neither a positive real, nor one of the above keywords is set, an error is signalled.

If the solver is AUTO-UPDATE, the variables will be updated after the strength is updated.

See CONSTRAINT (type)
See +REQUIRED+
See +STRONG+
See +MEDIUM+
See +WEAK+
See +NONE+

Package
Source

cassowary.lisp (file)

Writer

(setf strength) (function)

Function: (setf strength) STRENGTH CONSTRAINT
Package
Source

cassowary.lisp (file)

strength (function)

Function: suggest VARIABLE VALUE &optional IF-NOT-SUGGESTABLE

Suggest a particular value for the variable.

The solver will try to solve the system while keeping the value of the variable to the suggested value. Note however that this does not circumvent required constraints.

If the variable is not already suggestable, the value of if-not-suggestable becomes important. It may be one of the following: :ERROR — An error of type VARIABLE-NOT-SUGGESTABLE is signalled.
:MAKE-SUGGESTABLE — The variable is made suggestable with medium strength.
NIL — The function simply returns NIL.

If the solver is AUTO-UPDATE, the variables will be updated after this operation.

On success, returns the variable.

See VARIABLE (type)
See SUGGESTABLE-P
See MAKE-SUGGESTABLE
See MAKE-UNSUGGESTABLE
See VARIABLE-NOT-SUGGESTABLE

Package
Source

cassowary.lisp (file)

Function: suggestable-p VARIABLE

Returns true if the variable is suggestable.

See VARIABLE (type)
See MAKE-SUGGESTABLE
See MAKE-UNSUGGESTABLE
See SUGGEST

Package
Source

cassowary.lisp (file)

Function: update-variables SOLVER

Recomputes the variable values according to the current solver constraints.

You should call this function whenever you are done changing constraints or suggesting variables and would like to read out the
new, computed values for the variables.

Returns the solver.

See AUTO-UPDATE

Package
Source

cassowary.lisp (file)

Function: value VARIABLE

Returns the current value of the variable.

You might need to call UPDATE-VARIABLES on the solver before this returns an accurate value for the variable.

Note that for suggestable variables this might return a value different from the one previously suggested.

See VARIABLE (type)

Package
Source

constraint.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.5 Generic functions

Generic Function: expression CONDITION

Returns the expression associated with the object.

See EXPRESSION (type)
See EXPRESSION-UNSATISFIED
see EXPRESSION-UNBOUND

Package
Methods
Method: expression (CONDITION expression-unbound)
Source

conditions.lisp (file)

Method: expression (CONDITION expression-unsatisfied)
Source

conditions.lisp (file)

Generic Function: solver CONDITION

Returns the solver associated with the object.

See SOLVER (type)
See VARIABLE (type)
See CONSTRAINT (type)
See EXPRESSION-UNSATISFIED
See EXPRESSION-UNBOUND

Package
Methods
Method: solver (CONSTRAINT constraint)
Source

constraint.lisp (file)

Method: solver (VARIABLE variable)
Source

constraint.lisp (file)

Method: solver (CONDITION variable-not-suggestable)
Source

conditions.lisp (file)

Method: solver (CONDITION expression-unbound)
Source

conditions.lisp (file)

Method: solver (CONDITION expression-unsatisfied)
Source

conditions.lisp (file)

Generic Function: variable CONDITION

Returns the variable associated with the object.

See VARIABLE (type)
See VARIABLE-NOT-SUGGESTABLE

Package
Methods
Method: variable (CONDITION variable-not-suggestable)
Source

conditions.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.6 Conditions

Condition: assertion-violated ()

Error signalled when an internal assertion was violated.

This may arise due to invalid values being passed, or otherwise invalid sequences of operations being performed.

See CLASSOWARY-CONDITION
See CL:ERROR (type)

Package
Source

conditions.lisp (file)

Direct superclasses
Condition: classowary-condition ()

Supertype for all conditions related to Classowary.

See CL:CONDITION (type)

Package
Source

conditions.lisp (file)

Direct superclasses

condition (condition)

Direct subclasses
Condition: expression-unbound ()

Error signalled when an expression is unbound.

See CLASSOWARY-CONDITION
See CL:ERROR (type)
See SOLVER (function)
See EXPRESSION (function)

Package
Source

conditions.lisp (file)

Direct superclasses
Direct methods
Direct slots
Slot: solver
Initargs

:solver

solver (generic function)

Slot: expression
Initargs

:expression

expression (generic function)

Condition: expression-unsatisfied ()

Error signalled when it is impossible for the solver to satisfy an expression.

See CLASSOWARY-CONDITION
See CL:ERROR (type)
See SOLVER (function)
See EXPRESSION (function)

Package
Source

conditions.lisp (file)

Direct superclasses
Direct methods
Direct slots
Slot: solver
Initargs

:solver

solver (generic function)

Slot: expression
Initargs

:expression

expression (generic function)

Condition: variable-not-suggestable ()

Error signalled when attempting to suggest an unsuggestable variable.

When this error is signalled, two restarts must be active with the following behaviour:
MAKE-SUGGESTABLE — Makes the variable suggestable before setting the suggested value. The restart accepts an optional argument that sets the strength of the variable.
ABORT — Aborts the suggestion and returns NIL.

See CLASSOWARY-CONDITION
See CL:ERROR (type)
See SOLVER (function)
See VARIABLE (function)

Package
Source

conditions.lisp (file)

Direct superclasses
Direct methods
Direct slots
Slot: solver
Initargs

:solver

solver (generic function)

Slot: variable
Initargs

:variable

variable (generic function)

Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.7 Structures

Structure: constraint ()

Represents a constraint in a linear system.

Each of the constraints in a system must appear in the following normalised, mathematical form:

CONSTRAINT ::= TERM RELATION TERM (\+ TERM)*
RELATION ::= <= | = | >=
TERM ::= number (\* variable)?
number — a SINGLE-FLOAT
variable — a VARIABLE

For instance, the following are valid constraints:

0 = 0
1 = 2
1*x <= 1
2*x >= 3 + 4*y

And the following are not valid constraints:

1*x + 1*y = 3*y + 5*z
x*x = 2

See MAKE-CONSTRAINT
See CLONE-CONSTRAINT
See DELETE-CONSTRAINT
See FIND-CONSTRAINT
See REMOVE-CONSTRAINT
See RELATION
See SOLVER (function)
See CONSTRAIN

Package
Source

constraint.lisp (file)

Direct superclasses

structure-object (structure)

Direct methods
• solver (method)
• describe-object (method)
• print-object (method)
Direct slots
Slot: expression
Type

org.shirakumo.classowary:expression

Initform

(org.shirakumo.classowary::%make-expression (org.shirakumo.classowary::mksym (quote org.shirakumo.classowary::external)))

constraint-expression (function)

Writers

(setf constraint-expression) (function)

Slot: marker
Type

symbol

constraint-marker (function)

Writers

(setf constraint-marker) (function)

Slot: other
Type

symbol

constraint-other (function)

Writers

(setf constraint-other) (function)

Slot: relation
Type

symbol

constraint-relation (function)

Writers

(setf constraint-relation) (function)

Slot: strength
Type

single-float

Initform

0.0

constraint-strength (function)

Writers

(setf constraint-strength) (function)

Slot: solver
Type

org.shirakumo.classowary:solver

constraint-solver (function)

Writers

(setf constraint-solver) (function)

Structure: expression ()

The representation of a linear expression.

A linear expression represents a constant factor added together with a series of linear variable terms.

See TERM

Package
Source

expression.lisp (file)

Direct superclasses

structure-object (structure)

Direct methods
• describe-object (method)
• print-object (method)
Direct slots
Slot: key
Type

symbol

expression-key (function)

Writers

(setf expression-key) (function)

Slot: infeasible-p
Type

boolean

expression-infeasible-p (function)

Writers

(setf expression-infeasible-p) (function)

Slot: terms
Type

hash-table

Initform

(make-hash-table :test (quote eq))

expression-terms (function)

Writers

(setf expression-terms) (function)

Slot: constant
Type

single-float

Initform

0.0

expression-constant (function)

Writers

(setf expression-constant) (function)

Structure: solver ()

Represents a linear constraint system.

A linear constraint system is composed out of several constraints that describe an equality or inequality composed out of linear terms. The solver can then attempt to find a solution that fits the variables in the terms to the constraints as well as possible.

Note that the solver will bend constraints if there is no solution that does not violate any of them.

See CONSTRAINT (type)
See MAKE-SOLVER
See RESET-SOLVER
See AUTO-UPDATE
See MAKE-CONSTRAINT
See MAKE-VARIABLE
See CONSTRAIN
see WITH-VARIABLES
See FIND-VARIABLE
See FIND-CONSTRAINT

Package
Source

constraint.lisp (file)

Direct superclasses

structure-object (structure)

Direct methods
• describe-object (method)
• print-object (method)
Direct slots
Slot: objective
Type

org.shirakumo.classowary:expression

Initform

(org.shirakumo.classowary::%make-expression)

solver-objective (function)

Writers

(setf solver-objective) (function)

Slot: variables
Type

hash-table

Initform

(make-hash-table :test (quote eq))

solver-variables (function)

Writers

(setf solver-variables) (function)

Slot: constraints
Type

hash-table

Initform

(make-hash-table :test (quote eq))

solver-constraints (function)

Writers

(setf solver-constraints) (function)

Slot: expressions
Type

hash-table

Initform

(make-hash-table :test (quote eq))

solver-expressions (function)

Writers

(setf solver-expressions) (function)

Slot: infeasible-expressions
Type

list

solver-infeasible-expressions (function)

Writers

(setf solver-infeasible-expressions) (function)

Slot: dirty-variables
Type

list

solver-dirty-variables (function)

Writers

(setf solver-dirty-variables) (function)

Slot: auto-update
Type

boolean

solver-auto-update (function)

Writers

(setf solver-auto-update) (function)

Structure: term ()

The representation of a variable term.

A term is a variable and a linear multiplication factor.

Package
Source

expression.lisp (file)

Direct superclasses

structure-object (structure)

Direct methods
• describe-object (method)
• print-object (method)
Direct slots
Slot: key
Type

symbol

term-key (function)

Writers

(setf term-key) (function)

Slot: multiplier
Type

single-float

Initform

0.0

term-multiplier (function)

Writers

(setf term-multiplier) (function)

Structure: variable ()

Represents a variable in a linear system.

A variable can appear in an arbitrary number of constraints to express linear terms. A variable has a value and two states: suggestable, or unsuggestable. In the default, unsuggestable state, the variable is freely controlled by the linear system and its value is directly deduced from the constraints. In the suggestable state, the variable has a suggested value that the user supplies, which the solver should attempt to keep constant as the system is solved.

See MAKE-VARIABLE
See DELETE-VARIABLE
See FIND-VARIABLE
See WITH-VARIABLES
See SOLVER (function)
See MAKE-SUGGESTABLE
See MAKE-UNSUGGESTABLE
See SUGGESTABLE-P
See SUGGEST
See VALUE

Package
Source

constraint.lisp (file)

Direct superclasses

structure-object (structure)

Direct methods
• solver (method)
• describe-object (method)
• print-object (method)
Direct slots
Slot: symbol
Type

symbol

variable-symbol (function)

Writers

(setf variable-symbol) (function)

Slot: dirty-p
Type

boolean

variable-dirty-p (function)

Writers

(setf variable-dirty-p) (function)

Slot: constraint
Type

(or null org.shirakumo.classowary:constraint)

variable-constraint (function)

Writers

(setf variable-constraint) (function)

Slot: edit-value
Type

single-float

Initform

0.0

variable-edit-value (function)

Writers

(setf variable-edit-value) (function)

Slot: value
Type

single-float

Initform

0.0

variable-value (function)

Writers

(setf variable-value) (function)

Slot: solver
Type

org.shirakumo.classowary:solver

variable-solver (function)

Writers

(setf variable-solver) (function)

Previous: , Up: Definitions   [Contents][Index]

### 5.2 Internal definitions

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.1 Special variables

Special Variable: *symbol-ids*
Package
Source

symbol.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.2 Macros

Macro: do-constraints (CONSTRAINT SOLVER &optional RESULT) &body BODY
Package
Source

constraint.lisp (file)

Macro: do-expressions (EXPRESSION SOLVER &optional RESULT) &body BODY
Package
Source

constraint.lisp (file)

Macro: do-terms (TERM EXPRESSION &optional RESULT) &body BODY
Package
Source

expression.lisp (file)

Macro: do-variables (VARIABLE SOLVER &optional RESULT) &body BODY
Package
Source

constraint.lisp (file)

Macro: when-ok FORM &body BODY
Package
Source

conditions.lisp (file)

Macro: with-protection UNWIND &body PROTECTED
Package
Source

cassowary.lisp (file)

Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.3 Functions

Function: %make-constraint STRENGTH SOLVER &optional EXPRESSION
Package
Source

constraint.lisp (file)

Function: %make-expression &optional KEY
Package
Source

expression.lisp (file)

Function: %make-solver &key AUTO-UPDATE
Package
Source

constraint.lisp (file)

Function: %make-variable SYMBOL SOLVER
Package
Source

constraint.lisp (file)

Function: ->strength STRENGTH
Package
Source

toolkit.lisp (file)

Package
Source

constraint.lisp (file)

Package
Source

expression.lisp (file)

Package
Source

expression.lisp (file)

Package
Source

constraint.lisp (file)

Package
Source

cassowary.lisp (file)

Function: clear-expression EXPRESSION
Package
Source

expression.lisp (file)

Function: constant-p EXPRESSION
Package
Source

expression.lisp (file)

Function: constraint-expression INSTANCE
Function: (setf constraint-expression) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: constraint-marker INSTANCE
Function: (setf constraint-marker) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: constraint-other INSTANCE
Function: (setf constraint-other) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: constraint-p OBJECT
Package
Source

constraint.lisp (file)

Function: constraint-relation INSTANCE
Function: (setf constraint-relation) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: constraint-solver INSTANCE
Function: (setf constraint-solver) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: constraint-strength INSTANCE
Function: (setf constraint-strength) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: copy-constraint INSTANCE
Package
Source

constraint.lisp (file)

Function: copy-expression INSTANCE
Package
Source

expression.lisp (file)

Function: copy-solver INSTANCE
Package
Source

constraint.lisp (file)

Function: copy-term INSTANCE
Package
Source

expression.lisp (file)

Function: copy-variable INSTANCE
Package
Source

constraint.lisp (file)

Function: delta-edit-constant SOLVER DELTA CONSTRAINT
Package
Source

cassowary.lisp (file)

Function: dual-optimize SOLVER
Package
Source

cassowary.lisp (file)

Function: dummy-p SYMBOL
Package
Source

symbol.lisp (file)

Function: ensure-expression SYMBOL SOLVER
Package
Source

constraint.lisp (file)

Function: ensure-term SYMBOL EXPRESSION
Package
Source

expression.lisp (file)

Function: error-p SYMBOL
Package
Source

symbol.lisp (file)

Function: expression-constant INSTANCE
Function: (setf expression-constant) VALUE INSTANCE
Package
Source

expression.lisp (file)

Function: expression-infeasible-p INSTANCE
Function: (setf expression-infeasible-p) VALUE INSTANCE
Package
Source

expression.lisp (file)

Function: expression-key INSTANCE
Function: (setf expression-key) VALUE INSTANCE
Package
Source

expression.lisp (file)

Function: expression-p OBJECT
Package
Source

expression.lisp (file)

Function: expression-terms INSTANCE
Function: (setf expression-terms) VALUE INSTANCE
Package
Source

expression.lisp (file)

Function: external-p SYMBOL
Package
Source

symbol.lisp (file)

Function: find-expression SYMBOL SOLVER
Function: (setf find-expression) EXPRESSION SYMBOL SOLVER
Package
Source

constraint.lisp (file)

Function: find-term SYMBOL EXPRESSION
Function: (setf find-term) TERM SYMBOL EXPRESSION
Package
Source

expression.lisp (file)

Function: get-expression SOLVER SYMBOL DESTINATION
Package
Source

cassowary.lisp (file)

Function: get-leaving-expression SOLVER MARKER
Package
Source

cassowary.lisp (file)

Function: make-expression SOLVER CONSTRAINT
Package
Source

cassowary.lisp (file)

Function: make-term KEY &optional MULTIPLIER
Package
Source

expression.lisp (file)

Function: mark-dirty SOLVER VARIABLE
Package
Source

cassowary.lisp (file)

Function: mark-infeasible SOLVER EXPRESSION
Package
Source

cassowary.lisp (file)

Function: merge-constraint-into CONSTRAINT OTHER MULTIPLIER
Package
Source

constraint.lisp (file)

Function: merge-expression SOLVER EXPRESSION VARIABLE MULTIPLIER
Package
Source

cassowary.lisp (file)

Function: mksym TYPE &optional NAME
Package
Source

symbol.lisp (file)

Function: multiply EXPRESSION MULTIPLIER
Package
Source

expression.lisp (file)

Function: optimize-for OBJECTIVE SOLVER
Package
Source

cassowary.lisp (file)

Function: pivotable-p SYMBOL
Package
Source

symbol.lisp (file)

Function: put-expression SOLVER SYMBOL SOURCE
Package
Source

cassowary.lisp (file)

Function: reduce-expression THING
Package
Source

constraint.lisp (file)

Function: remove-errors SOLVER CONSTRAINT
Package
Source

cassowary.lisp (file)

Function: reset-expression EXPRESSION
Package
Source

expression.lisp (file)

Function: slack-p SYMBOL
Package
Source

symbol.lisp (file)

Function: solve-for EXPRESSION ENTRY EXIT
Package
Source

expression.lisp (file)

Function: solver-auto-update INSTANCE
Function: (setf solver-auto-update) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: solver-constraints INSTANCE
Function: (setf solver-constraints) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: solver-dirty-variables INSTANCE
Function: (setf solver-dirty-variables) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: solver-expressions INSTANCE
Function: (setf solver-expressions) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: solver-infeasible-expressions INSTANCE
Function: (setf solver-infeasible-expressions) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: solver-objective INSTANCE
Function: (setf solver-objective) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: solver-p OBJECT
Package
Source

constraint.lisp (file)

Function: solver-variables INSTANCE
Function: (setf solver-variables) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: substitute EXPRESSION ENTRY TO-SUBSTITUTE
Package
Source

expression.lisp (file)

Function: substitute-expressions SOLVER VARIABLE TO-SUBSTITUTE
Package
Source

cassowary.lisp (file)

Function: term-key INSTANCE
Function: (setf term-key) VALUE INSTANCE
Package
Source

expression.lisp (file)

Function: term-multiplier INSTANCE
Function: (setf term-multiplier) VALUE INSTANCE
Package
Source

expression.lisp (file)

Function: term-p OBJECT
Package
Source

expression.lisp (file)

Package
Source

cassowary.lisp (file)

Function: variable-constraint INSTANCE
Function: (setf variable-constraint) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: variable-dirty-p INSTANCE
Function: (setf variable-dirty-p) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: variable-edit-value INSTANCE
Function: (setf variable-edit-value) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: variable-p OBJECT
Package
Source

constraint.lisp (file)

Function: variable-solver INSTANCE
Function: (setf variable-solver) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: variable-symbol INSTANCE
Function: (setf variable-symbol) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: variable-value INSTANCE
Function: (setf variable-value) VALUE INSTANCE
Package
Source

constraint.lisp (file)

Function: write-sym SYMBOL STREAM
Package
Source

symbol.lisp (file)

Function: ~= A B
Package
Source

toolkit.lisp (file)

Function: ~zerop FLOAT
Package
Source

toolkit.lisp (file)

Previous: , Up: Top   [Contents][Index]

## Appendix A Indexes

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.1 Concepts

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.2 Functions

Jump to: %   (   -   ~   A   C   D   E   F   G   M   O   P   R   S   T   U   V   W
Jump to: %   (   -   ~   A   C   D   E   F   G   M   O   P   R   S   T   U   V   W

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.3 Variables

Jump to: *   +   A   C   D   E   I   K   M   O   R   S   T   V
Jump to: *   +   A   C   D   E   I   K   M   O   R   S   T   V

Previous: , Up: Indexes   [Contents][Index]