-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConstraintMaker.py
57 lines (54 loc) · 2.43 KB
/
ConstraintMaker.py
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
from collections import Counter
import random
def createRandomConstraint(ControlNodes, n, VandCOlength):
# generate a list consists of n constraints
# 0. If the number of v and co is smaller than 2, cannot support constraint type 2. Directly give type 1
# 1. Randomly choose the type of constraint
# 2. If type 1,
# 2-1. Randomly choose one control component (except control port) involved
# 3. If type 2,
# 3-1. Randomly choose two control components (except control port) involved
ConstraintList = []
i = 0
while i < n:
RepeatFlag = 0
ConstraintEquation = []
if VandCOlength < 2:
ConstraintType = 0
else:
ConstraintType = random.randint(0, 1)
if ConstraintType == 0:
while 1:
CtrlComponentNum = random.randint(0, len(ControlNodes) - 1)
if ControlNodes[CtrlComponentNum][0] == 'v' or ControlNodes[CtrlComponentNum][1] == 'o':
break
ConstraintNode = ControlNodes[CtrlComponentNum]
ConstraintEquation = [1, ConstraintNode]
else:
while 1:
CtrlComponentNum = random.randint(0, len(ControlNodes) - 1)
CtrlComponentNum2 = random.randint(0, len(ControlNodes) - 1)
if ControlNodes[CtrlComponentNum][0] == 'v' or ControlNodes[CtrlComponentNum][1] == 'o':
if ControlNodes[CtrlComponentNum2][0] == 'v' or ControlNodes[CtrlComponentNum2][1] == 'o':
while 1:
CtrlComponentNum2 = random.randint(0, len(ControlNodes) - 1)
if ControlNodes[CtrlComponentNum2][0] == 'v' or ControlNodes[CtrlComponentNum2][1] == 'o':
break
break
if CtrlComponentNum == CtrlComponentNum2:
RepeatFlag = 1
else:
ConstraintNode = ControlNodes[CtrlComponentNum]
ConstraintNode2 = ControlNodes[CtrlComponentNum2]
ConstraintEquation = [2, ConstraintNode, ConstraintNode2]
if RepeatFlag == 1:
continue
for ExistsEdge in ConstraintList:
if Counter(ConstraintEquation) == Counter(ExistsEdge):
RepeatFlag = 1
break
if RepeatFlag == 1:
continue
ConstraintList.append(ConstraintEquation)
i += 1
return ConstraintList