public static void refreshGateAttributes(Gate g, GateLibrary gate_library) { if (g.Type == GateType.OUTPUT || g.Type == GateType.OUTPUT_OR) { g.set_params(null); ArrayList<String> variable_names = new ArrayList<>(); variable_names.add("x"); g.set_variable_names(variable_names); HashMap<String, Double[]> variable_thresholds = new HashMap<>(); variable_thresholds.put("x", new Double[] {null, null}); g.set_variable_thresholds(variable_thresholds); String equation = String.valueOf("x"); g.set_equation(equation); } else if (gate_library.get_GATES_BY_NAME().containsKey(g.Name)) { g.set_params(gate_library.get_GATES_BY_NAME().get(g.Name).get_params()); if (g.get_variable_names().isEmpty()) { g.set_variable_names(gate_library.get_GATES_BY_NAME().get(g.Name).get_variable_names()); } g.set_variable_thresholds( gate_library.get_GATES_BY_NAME().get(g.Name).get_variable_thresholds()); g.set_equation(gate_library.get_GATES_BY_NAME().get(g.Name).get_equation()); g.System = gate_library.get_GATES_BY_NAME().get(g.Name).System; g.ColorHex = gate_library.get_GATES_BY_NAME().get(g.Name).ColorHex; g.Group = gate_library.get_GATES_BY_NAME().get(g.Name).Group; g.Regulator = gate_library.get_GATES_BY_NAME().get(g.Name).Regulator; g.Inducer = gate_library.get_GATES_BY_NAME().get(g.Name).Inducer; // if(Args.histogram) { if (gate_library.get_GATES_BY_NAME().get(g.Name).get_xfer_hist() != null) { g.set_xfer_hist(gate_library.get_GATES_BY_NAME().get(g.Name).get_xfer_hist()); } } else { g.System = "null"; g.ColorHex = "null"; g.Group = "null"; g.Regulator = "null"; g.Inducer = ""; } }
/** * A gate with two transcriptional units (e.g. AND) can have two different wirings. Doesn't matter * for a gate with one txn unit. * * @param g * @param gate_library * @param options */ public static void setBestVariableMapping(Gate g, GateLibrary gate_library, Args options) { ArrayList<ArrayList<String>> variable_name_orders = Permute.getVariableNamePermutation(g.get_variable_names()); Integer best_variable_name_order_index = 0; Double best_score = 0.0; int v = 0; for (ArrayList<String> variable_name_order : variable_name_orders) { g.get_outreus().clear(); for (int i = 0; i < g.get_logics().size(); ++i) { // rows in truth table /*if (Args.dontcare_rows.contains(i)) { g.get_outreus().add(0.0); continue; }*/ GateUtil.mapWiresToVariables(g, variable_name_order); double output_reu = ResponseFunction.computeOutput( GateUtil.getVariableValues(g, i, gate_library, options), g.get_params(), g.get_equation()); g.get_outreus().add(output_reu); } evaluateGate(g, options); if (g.get_scores().get_score() > best_score) { best_score = g.get_scores().get_score(); best_variable_name_order_index = v; } v++; } // this is the critical part, it's ordering the variable names in the list g.set_variable_names(variable_name_orders.get(best_variable_name_order_index)); }