-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.php
More file actions
299 lines (201 loc) · 6.88 KB
/
generate.php
File metadata and controls
299 lines (201 loc) · 6.88 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
include_once ("functions/pattern.php");
set_time_limit(600);
ini_set('memory_limit', '-1');
$valids = array();
if (isset($argv)) {
$lb = "\n";
$a = microtime(true);
if (isset($argv[2])) {
$group = isset($argv[3]) ? $arg[3] : false;
ob_start();
generate($argv[1], $argv[2], $argv[3], $valids);
ob_end_clean();
valids($valids, $lb);
} else {
ob_start();
generate_all($argv[1], $valids);
ob_end_clean();
valids($valids, $lb);
}
$b = microtime(true);
echo "\nTemps d'exécution : ".round($b-$a, 2)." secondes\n";
} else {
$lb = "<br/>";
if (!isset($_GET["c"])) {
return;
}
$p = (isset($_GET["p"])) ? $_GET["p"] : false;
$c = $_GET["c"];
//$entracts = (isset($_GET["entracts"])) ? $_GET["entracts"] : false;
$group = (isset($_GET["group"])) ? $_GET["group"] : false;
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'/><link rel='stylesheet' href='css/generate.css'/><title>Motifs dramatiques</title></head><body>";
if ($p) {
generate($c, $p, $group, $valids);
valids($valids, $lb);
} else {
generate_all($c, $valids);
valids($valids, $lb);
}
echo "</body></html>";
}
function valids($valids, $lb) {
$valids = entracts($valids);
//echo "<pre>";print_r($valids);
$total = count($valids);
if($lb == "\n"){echo "\nTotal : " . $total . " motifs valides\n";}else{
echo "<h2>Total : " . $total . " motifs valides</h2>";
}
//print_r($valids);
foreach ($valids as $pattern) {
$pattern = flatmulti($pattern);
$pattern = multiflip($pattern);
$pattern = intcode($pattern);
$pattern = multistring($pattern);
echo $pattern . $lb;
}
}
function entracts($valids){
$array = array();
//ne marche que pour l = 3, un seul entracte dans le motif
foreach($valids as $pattern){
//line = char
$characters_n = count($pattern);
$pattern = flatmulti($pattern);
$pattern = multiflip($pattern);
$pattern = multiflat($pattern);//line = conf
$line = str_repeat("0",$characters_n);
$new = array($pattern[0], $line, $pattern[1], $pattern[2]);
$new = flatmulti($new);
$new = multiflip($new);
$new = multiflat($new);
$array[] = $new;
$new = array($pattern[0], $pattern[1], $line, $pattern[2]);
$new = flatmulti($new);
$new = multiflip($new);
$new = multiflat($new);
$array[] = $new;
}
return $array;
}
function generate($c, $p, $group = false, &$valids) {
//générer tous les motifs
$i = 0;
$max = pow(2, ($p * $c));
$cp = $c * $p;
$patterns = $duplicates = $empty_char = $duplicate_char = $empty_conf = $repeat_conf = array();
//test
echo "<h2>s = " . $c . " scènes, p = " . $p . " personnages</h2><p>2<sup>sp</sup> = " . $max . " motifs possibles, de 0 à " . decbin($max - 1) . "<sub>2</sub></p>";
echo "<table><tr style='vertical-align:top;'><td><table><tr style='vertical-align:top;'><td><h3>Motifs possibles</h3>" . $max . " motifs</td><td><h3>Motifs possibles réordonnés</h3>" . $max . " motifs<br/><br/></td></tr>";
//
while ($i < $max) { //vérifier que je n'ai pas besoin de <=
$pattern = str_pad(decbin($i) , $cp, 0, STR_PAD_LEFT);
//vérifier que je n'ai pas besoin de (c*p)+1
//on dit que pattern = pers1(conf1, conf2), pers2(conf1, conf2) et flip_pattern = conf1(pers1, pers2), conf2(pers1, pers2)
$pattern = binflat($pattern, $c);
//test
echo "<tr><td>" . print_pattern($pattern) . "</td>";
//
$pattern = flatorder($pattern);
//test
echo "<td>" . print_pattern($pattern) . "</td></tr>";
//
$pattern = flatbin($pattern);
$patterns[] = $pattern;
$i++;
}
//test
echo "</tr></table></td>";
//
//virer les doublons de motif et afficher à part
$patterns = array_values(array_unique($patterns));
$array = array();
foreach ($patterns as $pattern) {
$array[] = binflat($pattern, $c);
}
$patterns = $array;
//test
echo "<td class='filtered'><h3>Motifs possibles dédoublonnés</h3>" . print_patterns($patterns) . "</td>";
//
foreach ($patterns as $key => $pattern) {
//personnage absent
if (flatempty($pattern)) {
unset($patterns[$key]);
//test
$empty_char[] = $pattern;
//
}
//grouper les personnages
if (flatduplicate($pattern)) { //
unset($patterns[$key]);
//test
$duplicate_char[] = $pattern;
//
}
$flip_pattern = flatmulti($pattern);
$flip_pattern = multiflip($flip_pattern);
$flip_pattern = multiflat($flip_pattern);
//configuration vide
if (flatempty($flip_pattern)) {
unset($patterns[$key]);
//test
$empty_conf[] = $pattern;
//
}
//configurations successives identiques
if (flatrepeat($flip_pattern)) {
unset($patterns[$key]);
//test
$repeat_conf[] = $pattern;
//
}
}
$valids = array_merge($valids, $patterns);
//test
echo "<td class='filtered'><h3>Motifs exclus</h3><h4>Motifs avec au moins un personnage toujours absent</h4>" . print_patterns($empty_char);
echo "<h4>Motifs avec au moins deux personnages concomittants</h4>" . print_patterns($duplicate_char);
echo "<h4>Motifs avec au moins une scène sans personnage</h4>" . print_patterns($empty_conf);
echo "<h4>Motifs avec au moins une scène identique à la suivante</h4>" . print_patterns($repeat_conf);
echo "</td><td class='filtered'><h3>Motifs valides</h3>" . print_patterns($patterns, true) . "</td></tr></table>";
//
return array_values($patterns);
}
function generate_all($c, &$valids) {
$max = (bcpow(2, $c)); //nombre max de personnages possibles ayant une distance > 0 avec ce nombre de configuration
//test
echo "<h1>s = " . $c . " scènes, 2<sup>s</sup>-1 = " . ($max - 1) . " personnages distincts possibles</h1>";
//
$p = 1;
$total = 0;
$patterns = array();
while ($p < $max) {
//test
echo "<h2>Motifs à " . $p . " personnages</h2>";
//
$patterns = array_merge($patterns, generate($c, $p, false, $valids));
//test
//
$p++;
}
//test
//
return $patterns;
}
//lenteur
//créer des motifs pour les entractes. Le faire en second, sur string (entracte à l'intérieur du motif)
//A-B/A/A-C
//A-B/A-B-C/A-C
//A/A-B/A
//A/A-B/B
//A/A-B/A-B-C
//A-B-C/A-B/A
//A/A-B-C/A-B
//A-B/A-B-C/A
//C. combinaisons regroupées
//rupture ?
//retour ?
//permanence ?
//alternance ?
//version terminal
//Mairet
?>