forked from zyrrron/Vespa-Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solenoids_merge.js
110 lines (104 loc) · 2.45 KB
/
solenoids_merge.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
// dynamicly analyse what is newly removed or added from/to open sets
function port_merge_split(a, b){
var d=[];
var b_left = [], a_left=[],keep_open=[],keep_close=[];
for (let element of a){
if (b.indexOf(element)<0) a_left[a_left.length] = element;
else keep_open[keep_open.length] = element;
}
for (let element of b){
if (keep_open.indexOf(element)<0) b_left[b_left.length] = element;
}
d[d.length] = keep_open;
d[d.length] = b_left;
d[d.length] = a_left;
return d;
}
function union_merge(a){
var c=[];
var k =0;
var la = a.length;
while(k<la){
if (k==0) {
d = port_merge_split(a[0],a[1]);
console.log(d.slice(0));
var i =0;
while (i < d.length){
if ( d[i].length>0 && c.indexOf(d[i]) < 0) c.push(d[i])
i++;
}
k++;
}
else{
var lc =c.length;
var a_left = a[k];
console.log(c.slice(0));
// split a[k] using current c
for (var j=0;j< lc;j++){
if (a_left.length<=0) break;
var d = [];
if (c[j].length>0){
d = port_merge_split(a_left,c[j])
a_left = d[d.length-1];
c.splice(j,1);
j--;
lc--;
var i = 0;
// don't scan the a_left in d.
while (i < d.length-1){
if ( d[i].length>0 && c.indexOf(d[i]) < 0) c.push(d[i]);
i++;
}
}
}
if (a_left.length>0) c.push(a_left);
}
k++;
}
// special to mode 5 of layout v1_i7
if (mode_a.indexOf(5)>=0) {
var lc = c.length;
for (var i =0; i<lc; i++){
console.log(c[i]);
if (c[i].indexOf(10)>=0){
console.log(i,c[i]);
var index = c[i].indexOf(10);
c[i].splice(index,1);
index = c[i].indexOf(11);
c[i].splice(index,1);
index = c[i].indexOf(12);
c[i].splice(index,1);
if (c[i].length == 0) c.splice(i,1);
c.push([10],[11],[12]);
break;
}
}
}
var i = 1;
close_ports = [];
var index = component_exist_list.indexOf("Port_control");
while (i<=component_each_info[index].length) {
var j = 0;
var flag = 0;
for (let ci of c){
if (ci.indexOf(i)>=0){
flag = 1;
break;
}
}
if (flag == 0) close_ports[close_ports.length] = i;
i++;
}
c.push(close_ports);
console.log(c);
return c;
}
function on_off(c,port_choose){
var switch_s = []
for (var i=0; i<c.length; i++){
if ( port_choose.indexOf(c[i][0]) >=0 ) switch_s[switch_s.length] = "on";
else switch_s[switch_s.length] = "off";
}
console.log(switch_s);
return switch_s;
}