forked from slightlyoff/cassowary.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariable.js
115 lines (100 loc) · 2.35 KB
/
Variable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (C) 1998-2000 Greg J. Badros
// Use of this source code is governed by http://www.apache.org/licenses/LICENSE-2.0
//
// Parts Copyright (C) 2011-2012, Alex Russell ([email protected])
(function(c) {
"use strict";
c.AbstractVariable = c.inherit({
isDummy: false,
isExternal: false,
isPivotable: false,
isRestricted: false,
_init: function(args, varNamePrefix) {
// Common mixin initialization.
this.hashCode = c._inc();
this.name = (varNamePrefix||"") + this.hashCode;
if (args) {
if (typeof args.name != "undefined") {
this.name = args.name;
}
if (typeof args.value != "undefined") {
this.value = args.value;
}
if (typeof args.prefix != "undefined") {
this._prefix = args.prefix;
}
}
},
_prefix: "",
name: "",
value: 0,
valueOf: function() { return this.value; },
toJSON: function() {
var o = {};
if (this._t) {
o._t = this._t;
}
if (this.name) {
o.name = this.name;
}
if (typeof this.value != "undefined") {
o.value = this.value;
}
if (this._prefix) {
o._prefix = this._prefix;
}
if (this._t) {
o._t = this._t;
}
return o;
},
fromJSON: function(o, Ctor) {
var r = new Ctor();
c.extend(r, o);
return r;
},
toString: function() {
return this._prefix + "[" + this.name + ":" + this.value + "]";
},
});
c.Variable = c.inherit({
_t: "c.Variable",
extends: c.AbstractVariable,
initialize: function(args) {
this._init(args, "v");
var vm = c.Variable._map;
if (vm) { vm[this.name] = this; }
},
isExternal: true,
});
/* static */
// c.Variable._map = [];
c.DummyVariable = c.inherit({
_t: "c.DummyVariable",
extends: c.AbstractVariable,
initialize: function(args) {
this._init(args, "d");
},
isDummy: true,
isRestricted: true,
value: "dummy",
});
c.ObjectiveVariable = c.inherit({
_t: "c.ObjectiveVariable",
extends: c.AbstractVariable,
initialize: function(args) {
this._init(args, "o");
},
value: "obj",
});
c.SlackVariable = c.inherit({
_t: "c.SlackVariable",
extends: c.AbstractVariable,
initialize: function(args) {
this._init(args, "s");
},
isPivotable: true,
isRestricted: true,
value: "slack",
});
})(this["c"]||module.parent.exports||{});