我正在尝试编写各种优化方法,作为一种修改方式.我希望能够使用SymPy在给定点评估具有任意数量变量的函数,其中点的坐标存储在数组中.
例如,我想评估f(x,y) = 3*x**2 - 2*x*y + y**2 + 4*x + 3*y一下b = [1,2].但我真的很喜欢这样做的一般方法,它可以处理具有任意数量变量的函数和适当长度的数组作为要评估的点,因此sympy.evalf(f, subs = {foo})实际上并不是非常有用.
我正在尝试用 C# 以编程方式打开远程桌面会话。我找到了这个教程,并遵循了它。我有一个仅包含AxMSTSCLib.AxMsRdpClient8NotSafeForScripting名为的表单rdp,然后我有以下代码:
public RDPViewer()
{
InitializeComponent();
rdp.Server = "localhost";
rdp.UserName = "<userName>";
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = "<password>";
rdp.Connect();
}
Run Code Online (Sandbox Code Playgroud)
(用户名和密码目前是硬编码的,这只是第一个测试,看看它是如何工作的)
但是,当我尝试运行它时,我收到一个错误弹出窗口:
连接无法继续,因为未启用身份验证,并且远程计算机需要启用身份验证才能连接。
谷歌搜索此错误发现几个网站指出此错误的解决方案是转到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp并将“SecurityLayer”值设置为 0,然后重新启动,但我已经这样做了,但仍然收到错误。
我已经进行了设置,因此可以通过 RDP 连接到本地主机,并且我可以使用与传入代码相同的凭据使用远程桌面连接进行连接。
我有一个双向命名管道。我不确定如何优雅地关闭它,但是,一旦完成,我会关闭-如果我从客户端关闭连接,则服务器端在尝试处置StreamReader和StreamWriter时会抛出异常。米使用。我目前正在抓住它,但是对我来说这似乎是一项艰巨的工作。
服务器端代码:
Thread pipeServer = new Thread(ServerThread);
pipeServer.Start();
private void ServerThread(object data)
{
int threadId = Thread.CurrentThread.ManagedThreadId;
log.Debug("Spawned thread " + threadId);
PipeSecurity ps = new PipeSecurity();
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
ps.AddAccessRule(new PipeAccessRule(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow));
ps.AddAccessRule(new PipeAccessRule(WindowsIdentity.GetCurrent().Owner, PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
log.Debug("Pipe security settings set [Thread " + threadId + "]");
NamedPipeServerStream pipeServer =
new NamedPipeServerStream("RDPCommunicationPipe", PipeDirection.InOut, numThreads, PipeTransmissionMode.Message, PipeOptions.None, 0x1000, 0x1000, ps);
log.Debug("Pipe Servers created");
// Wait for a client to connect
log.Info("Pipe created on thread " + threadId …Run Code Online (Sandbox Code Playgroud) 我有以下类定义:
class Codes():
def __new__(self, inp):
self.data = np.zeros((50,50))
self.capacity = 50
self.size = 6
self.data[:self.size,:self.size] = inp
self.x = 0
self.y = 0
return self
def __setitem__(self,coords,value):
x = coords[0]
y = coords[1]
if max(x,y) >= self.capacity:
self.capacity *= 2
newdata = np.zeroes((self.capacity,))
newdata[:self.size,:self.size] = self.data
self.data = newdata
self.data.__setitem__(coords,value)
if max(x,y) >= self.size:
print("expanding")
self.size = max(x,y)
print ("Debug")
def __getitem__(self,coords):
x = coords[0]
y = coords[1]
return self.data[x,y]
Run Code Online (Sandbox Code Playgroud)
似乎没有调用get和set方法.我正在初始化:
inp = np.array([[20151125,18749137,1728984,30943339,10071777,33511524],
[31916031,21629792,16929656,7726640,15514188,4041754],
[16080970,8057251,1601130,7981243,11661866,16474243],
[24592653,32451966,21345942,9380097,10600672,31527494],
[77061,17552253,28094349,6899651,9250759,31663883],
[33071741,6796745,25397450,24659492,1534922,27995004]]) …Run Code Online (Sandbox Code Playgroud)