array('6V.wisA/TP1', '6V.wisC/TP1'), '5H.kualg/TP1' => array('5H.kumu/TP1', '5H.kubv/TP1')) ); //array('5H.schk/TP1', '6V.wisD/TP1'), */ $db = mdb2_open($dsn); $buiten_beschouwing = array( // '5H.netl/TP2 ST lit', // '6V.netl/TP2 ST literatuur', ); $samenvoegen = array( // '5V.wisAC/TP2 ST1' => array('5V.wisA/TP2 ST1', '5V.wisC/TP2 ST1'), // '6V.wisAC/TP2 ST3' => array('6V.wisA/TP2 ST3', '6V.wisC/TP2 ST3'), ); $herinfo = get_herinfo($db); if (isset($_GET['period_id'])) $period_id = $_GET['period_id']; else $period_id = $herinfo['period_id']; $toetsen = get_toetsen_from_db($db, $period_id, $buiten_beschouwing, $samenvoegen); ksort($toetsen); $moments = mdb2_all_assoc_rekey($db, << count($colors)) error_system('te weinig kleuren'); $moment_to_color = array(); $color_to_moment = array(); foreach ($moments as $id => $moment) { $moment_to_color[$id] = count($color_to_moment); $color_to_moment[] = $id; $momentcolors .= "'moment-$id': '".$colors[$moment_to_color[$id]]."',"; } $max_colors = count($color_to_moment); foreach ($toetsen as $toets => $info) { $pta_id = mdb2_single_val($db, << $aantal) { if ($toetsen[$naam]['graph'] === NULL) { $collections[$id]['list'][] = $naam; set_graph_id($toetsen[$naam], $id); } } } $graph_id = 0; $collections = array(); foreach ($toetsen as $naam => &$value) { if ($value['graph'] !== NULL) continue; $collections[$graph_id] = array('list' => array($naam)); set_graph_id($value, $graph_id++); } unset($value); function set_colors_from_rooster() { global $toetsen, $moment_to_color, $color_to_moment, $rooster; foreach ($toetsen as $id => $info) { if (isset($rooster[$info['pta_id']])) { $toetsen[$id]['color'] = $moment_to_color[$rooster[$info['pta_id']]]; } else $toetsen[$id]['color'] = NULL; } } function check_consistent() { global $toetsen, $collections, $max_colors; set_colors_from_rooster(); foreach ($toetsen as $toets) { if ($toets['color'] === NULL) continue; foreach ($toets['neighbors'] as $neighbor => $tmp) { if ($toetsen[$neighbor]['color'] === $toets['color']) { ?>
faal voor
$tmp) { if ($toetsen[$neighbor]['color'] !== NULL) continue; $colors = array(); $colorless = array(); for ($i = 0; $i < $max_colors; $i++) $colors[$i] = 0; //echo("buren: $neighbor\n"); foreach ($toetsen[$neighbor]['neighbors'] as $second_neighbor => $tmp) { if ($toetsen[$second_neighbor]['color'] !== NULL) $colors[$toetsen[$second_neighbor]['color']]++; } $possible = 0; foreach ($colors as $color => $count) { if ($count > 0) continue; //echo("probeer $neighbor $color\n"); if (probeer_kleur($neighbor, $color, $max_colors)) { $possible++; break; } } if (!$possible) { $toetsen[$toets]['color'] = NULL; return false; } } return true; } ?> ok $info) { ?> [export]
$aantal) { if ($toetsen[$naam]['graph'] === NULL) { $collections[$id]['list'][] = $naam; set_graph_id($toetsen[$naam], $id); } } } $graph_id = 0; $collections = array(); foreach ($toetsen as $naam => &$value) { if ($value['graph'] !== NULL) continue; $collections[$graph_id] = array('list' => array($naam)); set_graph_id($value, $graph_id++); } unset($value); echo("aantal onafhankelijke sets: $graph_id\n"); */ function get_bad_colors(&$toetsen, &$c, $no, $max_colors, $add_undefined = false) { $bad_colors = array(); for ($i = 0; $i < $max_colors; $i++) $bad_colors[] = 0; if ($add_undefined) $bad_colors[NULL] = 0; // alle vertices met een lagere index zijn al gekleurd // en alle vertices met een hogere index zijn niet gekleurd // // visit all colored neighbors foreach ($toetsen[$c['list'][$no]]['neighbors'] as $neighbor => $count) { if ($c['indices'][$neighbor] > $no && !$add_undefined) break; $bad_colors[$toetsen[$neighbor]['color']]++; } return $bad_colors; } function beschouw(&$c, $no, $used_colors, $max_colors) { static $ret; global $toetsen; if ($no == 0) { $ret = array('colors' => array(), 'solutions' => array()); for ($i = 0; $i < count($c['list']); $i++) { $ret['colors'][$i] = array(); for ($j = 0; $j < $max_colors; $j++) $ret['colors'][$i][$j] = 0; } } if ((count($toetsen[$c['list'][$no]]['neighbors']) < $max_colors) || $no == count($c['list'])) { for ($i = $no; $i < count($c['list']); $i++) { $bad_colors = get_bad_colors($toetsen, $c, $i, $max_colors, true); if ($bad_colors[NULL]) continue; // er zijn onbekende buren, dan kunnen we niks $toetsen[$c['list'][$i]]['color'] = array(); for ($j = 0; $j < $max_colors; $j++) if (!$bad_colors[$j]) $toetsen[$c['list'][$i]]['color'][] = $j + 1; } //dot($c['list'], "out".sprintf("%04d", $counter++).".dot"); $solution = array(); for ($i = 0; $i < count($c['list'])/*$no*/; $i++) { if ($toetsen[$c['list'][$i]]['color'] === NULL) { $solution[] = '*'; } else if (!is_array($toetsen[$c['list'][$i]]['color'])) { $ret['colors'][$i][$toetsen[$c['list'][$i]]['color']]++; $solution[] = $toetsen[$c['list'][$i]]['color']; } else { if (count($toetsen[$c['list'][$i]]['color']) == 1) { $ret['colors'][$i][$toetsen[$c['list'][$i]]['color'][0] - 1]++; $solution[] = $toetsen[$c['list'][$i]]['color'][0] - 1; } else { $temp = array(); for ($j = 0; $j < count($toetsen[$c['list'][$i]]['color']); $j++) { $ret['colors'][$i][$toetsen[$c['list'][$i]]['color'][$j] - 1]++; $temp[] = $toetsen[$c['list'][$i]]['color'][$j] - 1; } $solution[] = $temp; } } } $ret['solutions'][] = $solution; for ($i = $no; $i < count($c['list']); $i++) { $toetsen[$c['list'][$i]]['color'] = NULL; } } else { $bad_colors = get_bad_colors($toetsen, $c, $no, $max_colors); foreach ($bad_colors as $color => $badness) { if ($badness > 0) continue; $toetsen[$c['list'][$no]]['color'] = $color; if ($color < $used_colors) { beschouw($c, $no + 1, $used_colors, $max_colors); } else if ($color == $used_colors) { // if a color never has been used before, mark it used beschouw($c, $no + 1, $used_colors + 1, $max_colors); } // else: do nothing } $toetsen[$c['list'][$no]]['color'] = NULL; } if ($no == 0) return $ret; } $max_max_colors = 1; foreach ($collections as &$collection) { usort($collection['list'], function ($a, $b) use (&$toetsen) { return count($toetsen[$a]['neighbors']) < count($toetsen[$b]['neighbors']); }); $collection['indices'] = array(); for ($i = 0; $i < count($collection['list']); $i++) { $collection['indices'][$collection['list'][$i]] = $i; } foreach ($collection['list'] as $toets) { uksort($toetsen[$toets]['neighbors'], function ($a, $b) use (&$collection) { return $collection['indices'][$a] > $collection['indices'][$b]; }); } $dot = dot($collection['list'], $toetsen); $collection['filename'] = $svg_filename = $datadir.md5($dot).'.svg'; if (!file_exists($svg_filename)) { $dot_filename = tempnam(sys_get_temp_dir(), 'her'); //if (file_put_contents($datadir.md5($dot).'.dot', $dot) === FALSE) error_system('unable to write .dot file'); if (file_put_contents($dot_filename, $dot) === FALSE) error_system('unable to write .dot file'); $out = system("dot -Tsvg -o$svg_filename $dot_filename", $ret); if ($ret != 0) error_system("error $ret creating .svg from .dot: $out"); unlink($dot_filename); } $max_colors = 0; do { $max_colors++; $collection['max_colors'] = $max_colors; $collection['solver'] = beschouw($collection, 0, 0, $max_colors); $no_solutions = count($collection['solver']['solutions']); } while (!$no_solutions); if ($max_colors > $max_max_colors) $max_max_colors = $max_colors; echo("
");
	echo("required colors: $max_colors, no_solutions=$no_solutions\n");

	foreach ($ret['solutions'] as $solution) {
		foreach ($solution as $color) echo($color);
		echo("\n");
	}

	foreach ($collection['list'] as $toets) {
		echo($toets.' '."{$toetsen[$toets]['color']}\n");
	}
	echo("
"); } unset($collection); $colors = array("#fbb4ae", "#b3cde3", "#ccebc5", "#decbe4", "#fed9a6", "#ffffcc", "#e5d8bd", "#fddaec", "#f2f2f2"); $colors['*'] = "#ffffff"; $colors['?'] = "#ffffff"; $gradients = array(); foreach ($collections as &$collection) { for ($i = 0; $i < count($collection['solver']['solutions']); $i++) { $colorset = ''; foreach ($collection['indices'] as $idx) { //echo("$idx\n"); //echo($toetsen[$collection['list'][$idx]]['id'].' color: '.$collection['solver']['solutions'][0][$idx]."\n"); $color = $collection['solver']['solutions'][$i][$idx]; if (!is_array($color) && $colors[$color]) $colorset .= "\$('#n".$toetsen[$collection['list'][$idx]]['id']." > polygon').attr('fill', '".$colors[$color]."');\n"; else if (is_array($color) && count($color) > 1) { $gradname = 'grad'.implode('', $color); $colorset .= "\$('#n".$toetsen[$collection['list'][$idx]]['id']." > polygon').attr('fill', 'url(#$gradname)');\n"; if (!isset($gradients[$gradname])) { $grad = ''."\n"; for ($j = 0; $j < count($color); $j++) { $grad .= ''."\n"; $grad .= ''."\n"; } $grad .= ''."\n"; //echo("test $gradname ->$grad<-\n"); $gradients[$gradname] = $grad; } } } $collection['solver']['scripts'][] = $colorset; } //print_r($collection['solver']['solutions'][0]); } unset($collection); // disallow freak behavior in php with foreach and & html_start(<<

ST's die buiten beschouwing zijn gelaten:


ST's die gekoppeld zijn:


Toetsgroep\n"); ?>Oplossing(en): '.$i.''); } echo(', benodigd aantal kleuren '.$collection['max_colors'].'.'); ?>
[export]