7.11
5220 作业
"""
First constraint propagator module: the True constraint.
"""
import sprue
from sprue.propagator import Propagator, post
from sprue.var import IntVar, Event
def register_handlers(registry):
registry.register_propagator('atmost', post_atmost)
def post_atmost(solver, args, anns):
return post(solver, AtMost, args[0], args[1])
class AtMost(Propagator):
"""
Fill in propagator methods:
"""
def __init__(self, solver, bool_vars, limit):
super().__init__(self)
self._bool_vars = [b for b in bool_vars if isinstance(b,Var) and b.lb() == 0]
self._limit = solver.state.make_value(limit - sum([1 for b in bool_vars if b == True or isinstance(b,Var) and b.lb() == 1]))
for b in self._bool_vars:
b.attach_on(True,self.wakeup)
def wakeup(self,solver):
self._limit.set(solver,self._limit.value()-1)
if self._limit.value() <= 0:
self.queue(solver)
def propagate(self,solver):
# count = 0;
# for b in self._bool_vars:
# if b.lb() == 1:
# count += 1
# print(f"%%{count}?{self._limit}")
# return count <= self._limit
if self._limit.value() == 0:
for b in self._bool_vars:
if b.lb() == 0:
if not b.set_false(solver):
return False
return True
from sprue.propagator import Propagator, post
from sprue.var import IntVar, Event, to_var, Var, negate, ConstView, Negation
def register_handlers(registry):
registry.register_propagator('my_alldifferent_except_0', AllDiffEx0Prop)
def post_AllDiffEx0Prop(Propagator):
return post(solver,AllDiffEx0Prop,args,anns)
class AllDiffEx0Prop(Propagator):
def __init__(self, solver, args, anns): # args is is the argument the ann annotation
super().__init__(self)
#self.args=[to_var(b) for b in args]
self.args=args[0]
self.num=len(self.args) #The number of elements in the array
for j in self.args:
j.attach_event(Event.DOM,self.wakeup)
def wakeup(self,solver):
self.queue(solver)
def propagate(self, solver):
for i in range(len(self.args)):
if (self.args[i].is_fixed())and(self.args[i].value()!=0) :
for j in range(len(self.args)):
if not self.args[j].is_fixed():
self.args[j].remove_value(solver, self.args[i].value())
else:
if self.args[i].value()==self.args[j].value()and(self.args[i]!=self.args[j]):
return False
return True
今日面向面经:Shopee 一面
- 查看cpu占用情况的命令,内存呢
- 查看磁盘占用情况的命令
- 怎么查看文件描述符
- BufferCache是什么?有什么作用?
- TCP四次挥手的具体过程
- 为什么四次,三次可能出现什么情况
- 服务端收到客户端FIN报文后,可以把它的ACK和FIN一起发出去,变成三次挥手吗
- Keepalive是什么,具体过程
- 除了TCP,应用层用到了Keepalive吗
- 为什么要额外实现Keepalive,有什么好处?
- 用户层面实现这个心跳检测机制有什么用,有什么是TCP的Keepalive做不到的但用户层面可以做到的?
- 滑动窗口是什么,为什么要有滑动窗口
- 如果没有滑动窗口,客户端也可以一下发很多包出来,会出现什么问题
- 一个sql语句,分析一下,怎么建索引
- 为什么要建联合索引,最左前缀
- 稍微改一下,能命中索引吗,怎么优化
- 联合索引失效,索引下推
- Join知道吗?Join索引呢
- 事务隔离级别,具体怎么实现的
- MVCC是什么,作用呢,怎么实现的
- undo log怎么实现的MVCC
- LRU是什么,怎么实现的,mysql用到了吗?做了什么优化,为什么这么做
- 一个购物车算最接近余额的题,我以为是背包,想错了没做出来,后来面试官说直接穷举,我也太蠢了,直接凉透
一些细节想不起来了,基本追问的问题就没答出来过