switchtodesign; deleteall; closeall; ############################# #set control switch_control = 5; routing_control = [1, 0, 0, 0, 1; 0, 0, 0, 1, 0; 0, 0, 1, 0, 0; 0, 1, 0, 0, 0]; ############################# #----------------------------------------------------------------# ##position of the elements device_heigth = 800; n1 = 4; hspace = 0; vspace = device_heigth / n1; for(i=1:n1) { auto_name = addelement( "Optical Switch"); switch_name = "S_1_" + num2str(i); setnamed( auto_name, "name", switch_name ); setposition(switch_name, 2*hspace, i*vspace); setnamed(switch_name, "control", routing_control(i, 1)); hspace = hspace + 40; } #hspace = hspace + vspace; n2 = 4; vspace = device_heigth / n2; for(i=1:n2) { auto_name = addelement( "Optical Switch"); switch_name = "S_2_" + num2str(i); setnamed( auto_name, "name", switch_name ); setposition(switch_name, 2*hspace, i*vspace); setnamed(switch_name, "control", routing_control(i, 2)); hspace = hspace + 40; } #hspace = hspace + vspace; n3 = 4; vspace = device_heigth / n3; for(i=1:n3) { auto_name = addelement( "Optical Switch"); switch_name = "S_3_" + num2str(i); setnamed( auto_name, "name", switch_name ); setposition(switch_name, 2*hspace, i*vspace); setnamed(switch_name, "control", routing_control(i, 3)); hspace = hspace + 40; } #hspace = hspace + vspace; n4 = 4; vspace = device_heigth / n4; for(i=1:n4) { auto_name = addelement( "Optical Switch"); switch_name = "S_4_" + num2str(i); setnamed( auto_name, "name", switch_name ); setposition(switch_name, 2*hspace, i*vspace); setnamed(switch_name, "control", routing_control(i, 4)); hspace = hspace + 40; } #hspace = hspace + vspace; n5 = 4; vspace = device_heigth / n5; for(i=1:n5) { auto_name = addelement( "Optical Switch"); switch_name = "S_5_" + num2str(i); setnamed( auto_name, "name", switch_name ); flipelement( switch_name ); setposition(switch_name, 2*hspace, i*vspace); setnamed(switch_name, "control", routing_control(i, 5)); hspace = hspace + 40; } #hspace = hspace + vspace; #----------------------------------------------------------------# ##CONNECTIONS for (ii = 1 : n1) { index1 = ii; index2 = ii; switch_name_1 = "S_1_" + num2str(index1); switch_name_2 = "S_2_" + num2str(index2); switch_name_3 = "S_2_" + num2str(mod(index2 + n2/2 - 1,4) + 1); if (ii <= 2) { connect(switch_name_1, "port 3", switch_name_2, "port 1"); connect(switch_name_1, "port 4", switch_name_3, "port 1"); } else { connect(switch_name_1, "port 4", switch_name_2, "port 2"); connect(switch_name_1, "port 3", switch_name_3, "port 2"); } } for (ii = 1 : n2) { index1 = ii; index2 = ii; switch_name_1 = "S_2_" + num2str(index1); switch_name_2 = "S_3_" + num2str(index2); switch_name_3 = "S_3_" + num2str(4 - mod(index2 + 1,4)); if (mod(ii, 2) == 1) { connect(switch_name_1, "port 3", switch_name_2, "port 1"); connect(switch_name_1, "port 4", switch_name_3, "port 1"); } else { connect(switch_name_1, "port 4", switch_name_2, "port 2"); connect(switch_name_1, "port 3", switch_name_3, "port 2"); } } for (ii = 1 : n3) { index1 = ii; index2 = ii; switch_name_1 = "S_3_" + num2str(index1); switch_name_2 = "S_4_" + num2str(index2); switch_name_3 = "S_4_" + num2str(4 - mod(index2 + 1,4)); if (mod(ii, 2) == 1) { connect(switch_name_1, "port 3", switch_name_2, "port 1"); connect(switch_name_1, "port 4", switch_name_3, "port 1"); } else { connect(switch_name_1, "port 4", switch_name_2, "port 2"); connect(switch_name_1, "port 3", switch_name_3, "port 2"); } } for (ii = 1 : n4) { index1 = ii; index2 = ii; switch_name_1 = "S_4_" + num2str(index1); switch_name_2 = "S_5_" + num2str(index2); switch_name_3 = "S_5_" + num2str(mod(index2 + n2/2 - 1,4) + 1); if (ii <= 2) { connect(switch_name_1, "port 3", switch_name_2, "port 3"); connect(switch_name_1, "port 4", switch_name_3, "port 3"); } else { connect(switch_name_1, "port 4", switch_name_2, "port 4"); connect(switch_name_1, "port 3", switch_name_3, "port 4"); } } #----------------------------------------------------------------# ##Create Compound n = 8; x_pos = -200; y_pos = device_heigth / n; selectall; createcompound; COMP_name = "SWITCH"; set("name", COMP_name); setposition(COMP_name, 200, 200); for (i = 1 : n) { addport("SWITCH", "input_" + num2str(i), "Input", "Optical Signal", "left"); } for (j = 1 : n) { addport("SWITCH", "output_" + num2str(j), "Output", "Optical Signal", "right"); } autoarrange("SWITCH",1); #connections for (i = 1 : n) { #input select("SWITCH::RELAY_" + num2str(i)); set("x position", x_pos); set("y position", (i + 1) * y_pos); if (mod(i, 2) == 1) { connect("SWITCH::RELAY_" + num2str(i), "output", "SWITCH::S_1_" + num2str(ceil(i/2)), "port 1"); } else { connect("SWITCH::RELAY_" + num2str(i), "output", "SWITCH::S_1_" + num2str(i/2), "port 2"); } #output select("SWITCH::RELAY_" + num2str(i + n)); set("x position", 2 * hspace + 100); set("y position", (i + 1) * y_pos); if (mod(i, 2) == 1) { connect("SWITCH::RELAY_" + num2str(i + n), "input", "SWITCH::S_5_" + num2str(ceil(i/2)), "port 1"); } else { connect("SWITCH::RELAY_" + num2str(i + n), "input", "SWITCH::S_5_" + num2str(i/2), "port 2"); } } #set property string1 = "routing_control = [" + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) +";\n"; string2 = " " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) +";\n"; string3 = " " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) +";\n"; string4 = " " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) + ", " + num2str(0) +"];\n" + endl; string5 = "for (i = 1 : 5) {\n for (j = 1 : 4) {\n switch_name = \"S_\" + num2str(i) + \"_\" + num2str(j);\n setnamed(switch_name, \"control\", routing_control(j, i));\n }\n}"; setnamed("SWITCH", "setup script", string1 + string2 + string3 + string4 + string5);