Python中文
首页
教程
问答
标签
搜索
登录
注册
如何用代码表示组合电路
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在编写一个python程序,它对组合电路执行一些操作,比如比较与其他电路的相等性、合并门、计数门、计数连接、查找扇出门等等</p> <p>现在,我用以下方式表示组合电路:<br/> (我还添加了平等性测试)</p> <pre><code>class Circuit: def __init__(self): self.gates = {} # key = the gates number, value = the gate def __eq__(self, other): if set(self.gates.keys()) != set(other.gates.keys()): return False for key in self.gates.keys(): if self.gates[key] != other.gates[key]: return False return True class Gate: def __init__(self, gate_type, number): self.gate_type = gate_type # and, or, nand, nor, xor, xnor self.number = number self.incoming_gates = [] self.outgoing_gates = [] def __eq__(self, other): # i know this is not correct, but in my case correct enough return ( self.gate_type == other.gate_type and self.number == other.number and len(self.incoming) == len(other.incoming) and len(self.outgoing) == len(other.outgoing) ) </code></pre> <p>我在代码中的表示对我来说似乎非常费力,所以我正在寻找更好的方法来实现这一点。我已经搜索了这方面的最佳实践,但没有找到任何东西</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您可以通过只存储入站门引用来避免门类中的冗余,但这会使代码的其余部分实现起来更加复杂。我相信冗余和易用性的权衡应该有利于易用性</p> <p>我不知道如何实现门之间的连接,但如果在self.incoming_gates/self.outing_gates中保存对象引用,则可能仅基于传入链接定义它们,并使用self自动更新源的传出_gate列表(可能在构造函数本身中)</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在PyObj中使用respondsToSelector和performSelector
7 回答
如何在pyobj中停止线程
6 回答
如何在pyobj中生成线程
5 回答
如何在pyodbc中为记录集指定游标类型?
4 回答
如何在pyodbc中从用户处获取表名,同时避免SQL注入?
5 回答
如何在pyodbc中使用executemany运行多个SELECT查询
9 回答
如何在pyodbc中同时在n个游标上并行运行n个进程?
4 回答
如何在pyodbc中控制连接池的大小?
7 回答
如何在pyodbc中自动调用fetchall()而不进行异常处理?
1 回答
如何在pyODBC查询中参数化日期戳?
3 回答
如何在pyodbc输出转换器函数中解压sqlserver DATETIME?
7 回答
如何在pyodb中安装所有驱动程序
3 回答
如何在pyodb嵌套循环中调用不同的查询
4 回答
如何在pyomo.environ公司modu装置
4 回答
如何在Pyomoconstraints中建模逻辑或量词
7 回答
如何在Pyomo中为约束使用数组
5 回答
如何在pyomo中使用集和范围集的多级索引?
4 回答
如何在PYOMO中分配伪二进制变量
10 回答
如何在Pyomo中创建OR约束?
7 回答
如何在Pyomo中动态地将变量添加到列表中?
1 回答