我有一个包含以下格式的30,000条记录的数据框:
ID | Name | Latitude | Longitude | Country |
1 | Hull | 53.744 | -0.3456 | GB |
Run Code Online (Sandbox Code Playgroud)
我想选择一条记录作为起始位置,将一条记录作为目标,并返回最短路径的路径(列表).
我使用Geopy来找到以km为单位的点之间的距离
import geopy.distance
coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)
print (geopy.distance.vincenty(coords_1, coords_2).km)
Run Code Online (Sandbox Code Playgroud)
我已经从以下教程中了解了如何在python中执行A*:https: //www.redblobgames.com/pathfinding/a-star/implementation.html
然而,他们创建了一个网格系统来浏览.
这是我到目前为止的代码,但它找不到路径:
def calcH(start, end):
coords_1 = (df['latitude'][start], df['longitude'][start])
coords_2 = (df['latitude'][end], df['longitude'][end])
distance = (geopy.distance.vincenty(coords_1, coords_2)).km
return distance
Run Code Online (Sandbox Code Playgroud)
^计算点之间的距离
def getneighbors(startlocation):
neighborDF = pd.DataFrame(columns=['ID', 'Distance'])
coords_1 = (df['latitude'][startlocation], df['longitude'][startlocation])
for index, row in df.iterrows():
coords_2 = (df['latitude'][index], df['longitude'][index]) …Run Code Online (Sandbox Code Playgroud) 我从数据库中获取一些数据并将其存储在全局变量中,如下所示:
//Global Variable
public static List<stuff> Stuff;
using (var context = new StuffContext())
{
stuff = new List<stuff>();
stuff = (from r in context.Stuff
select r).ToList();
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是上下文关闭,当我希望访问存储在全局变量中的一些数据时,我不能.
数据是System.Data.Entity.DynamicProxies.Stuff而不是Application.Model.Stuff,这意味着当我尝试对数据执行某些操作时,我会收到此错误:
"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."
Run Code Online (Sandbox Code Playgroud)
我的问题是,我如何使用上面的代码作为示例,转换/转换为我想要的类型,以便我可以在我的应用程序中使用其他数据?
我正在尝试用 C++ 创建二叉树数据结构的深层副本。问题是我使用的代码似乎只给了我一个浅拷贝(这似乎导致我的解构函数出现问题)。
下面的代码是我的二叉树复制构造函数:
BinaryTreeStorage::BinaryTreeStorage(const BinaryTreeStorage ©tree):root(NULL)
{
root = copytree.root;
copyTree(root);
}
BinaryTreeStorage::node* BinaryTreeStorage::copyTree(node* other)
{
//if node is empty (at bottom of binary tree)
/*
This creates a shallow copy which in turn causes a problem
with the deconstructor, could not work out how to create a
deep copy.
*/
if (other == NULL)
{
return NULL;
}
node* newNode = new node;
if (other ->nodeValue == "")
{
newNode ->nodeValue = "";
}
newNode->left = copyTree(other->left);
newNode->right …Run Code Online (Sandbox Code Playgroud) 我正在制作ASP.net MVC应用程序我希望如此,当用户点击链接时,它会执行ajax调用,将数据发送到控制器,然后将其他数据返回给视图.
这是我想在我的控制器中调用的方法:
public JsonResult GetImage(string url)
{
Image image = Image.FromFile(url, true);
byte[] byteImage = converter.ImageToBytes(image);
return Json(new { byteImage }, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
这里是控制器位置:
08983ClassLibrary\EpostASP\Controllers\CustomerController.cs
Run Code Online (Sandbox Code Playgroud)
这是我的Ajax调用:
$.ajax({
url: "~/Controllers/CustomerController/GetImage/",
type: 'POST',
contentType: 'application/json',
data: "url="+url,
success: function (image) {
document.getElementById("image").src = "data:image/png;base64," + image;
showImage();
}
});
Run Code Online (Sandbox Code Playgroud)
当我在代码中放置断点时,我可以看到它击中了ajax调用,然后踩到它从未到达控制器并且不会给出任何错误.有任何想法吗?
我有两套:
a = set(['this', 'is', 'an', 'apple!'])
b = set(['apple', 'orange'])
Run Code Online (Sandbox Code Playgroud)
我想找出 (a) 中是否有任何 (b) 包括子字符串。通常我会这样做:
c = a.intersection(b)
Run Code Online (Sandbox Code Playgroud)
然而,在这个例子中,它会返回一个空集 'apple' != 'apple!'
假设我无法从 (a) 中删除字符并且希望不创建循环,有没有办法让我找到匹配项?
编辑:我希望它从 (b) 返回匹配项,例如我想知道“苹果”是否在集合 (a) 中,我不希望它返回“苹果!”
目前,我正在使用反射在程序集中搜索实现接口的类,然后检查这些类的名称以查看它是否与搜索到的类相匹配。
我的下一个任务是向此代码添加一种在目录中搜索 DLL 文件的方法,我唯一的提示是我可以使用“System.Environment.CurrentDirectory”。我还需要考虑到并非所有 DLL 都包含 .net 程序集这一事实。
有人可以推荐从哪里开始吗?
IInstruction instruction = null;
string currentDir = Environment.CurrentDirectory;
var query = from type in Assembly.GetExecutingAssembly().GetTypes()
where type.IsClass && type.GetInterfaces().Contains(typeof(IInstruction))
select type;
foreach (var item in query)
{
if (opcode.Equals(item.Name, StringComparison.InvariantCultureIgnoreCase))
{
instruction = Activator.CreateInstance(item) as IInstruction;
return instruction;
}
}
Run Code Online (Sandbox Code Playgroud)
操作码是我正在搜索的类的名称。
我正在开发2个应用程序,第一个是C#控制台应用程序,另一个是Asp.net Web应用程序.我正在使用SignalR连接两者.
这是我的C#控制台应用程序(客户端)
public class RoboHub
{
public static IHubProxy _hub;
public RoboHub()
{
StartHubConnection();
_hub.On("GetGoals", () => GetGoals());
_hub.On("PrintMessageRobot", x => PrintMessageRobot(x));
Thread thread = new Thread(MonitorHubStatus);
thread.Start();
}
public void GetGoals()
{
//TODO: Does stuff
}
public void PrintMessageRobot(string msg)
{
Console.WriteLine(msg);
}
public void StartHubConnection()
{
Console.WriteLine("Robo Hub Starting");
string url = @"http://localhost:46124/";
var connection = new HubConnection(url);
_hub = connection.CreateHubProxy("WebHub");
connection.Start().Wait();
Console.WriteLine("Robo Hub Running");
}
public void MonitorHubStatus()
{
while (true)
{
Thread.Sleep(1000);
_hub.Invoke("Ping", "ping").Wait();
Console.WriteLine("WebHub …Run Code Online (Sandbox Code Playgroud) 我目前有一个很大的类对象列表,我目前正在使用以下lambda函数来返回满足条件的元素.
var call = callList.Where(i => i.ApplicationID == 001).ToList();
Run Code Online (Sandbox Code Playgroud)
这将返回所有id为001的对象列表.
我现在很好奇有什么不同的ApplicationID.所以我想要一个lambda函数来查看这个列表并返回一个列表,其中所有元素都有不同的ApplicationID,但只提取其中一个.
我试图在python中创建一个应用程序(使用tweepy apis)来收听包含Emojis的推文.
我想检索包含表情符号的所有推文:'U + 1F603','\ xF0\x9F\x98\x83'.
问题是尝试设置监听器来监听这些推文.
我正在使用Spyder和Python 2.7
#Set twitter stream
twitterStream = Stream(auth, listener())
twitterStream.filter(track=[tracker], languages = ["en"], stall_warnings = True, async=True)
Run Code Online (Sandbox Code Playgroud)
这是我设置流的代码.这似乎适用于除表情符号之外的任何文本.
我试过了:
tracker = "\xF0\x9F\x98\x83"
tracker = "U+1F603"
Run Code Online (Sandbox Code Playgroud)
我无法将表情符号粘贴到IDE中,因为它将其转换为字节,上面的代码将侦听文本(字节或unicode)而不是表情符号本身.
有没有人有任何建议?
我正在尝试搜索字典以查看它是否具有某个值,如果是,则更改它.这是我的代码:
foreach (var d in dictionary)
{
if (d.Value == "red")
{
d.Value = "blue";
}
}
Run Code Online (Sandbox Code Playgroud)
在visual studio中,当我逐步调试代码时,我可以看到它改变了值,然后当它到达foreach循环再次重复它会抛出异常
"集合已被修改;枚举操作可能无法执行"
我该如何解决?
我要做的是检查是否选中了列表框中的项目.
该方法正在一个单独的线程上运行,所以我需要使用我相信的方法调用程序.
string list = "";
lbxList.Invoke(new MethodInvoker(delegate { list = lbxList.SelectedItem.ToString(); }));
if (list != null)
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
如果所选项目为null,则此代码将会爆炸,因为字符串列表不会保留它,因此我需要一种方法将前2行组合成if语句检查null.
谢谢
我试图解决我的程序中的一些问题,看起来我的复制构造函数或我的析构函数有问题.我得到了一个内存异常.
任何帮助我都会感谢谢谢
ArrayStorage::ArrayStorage(const ArrayStorage &a):readArray(a.readArray),arraysize(a.arraysize)
{
readArray = new string[arraysize]; //create the array
memcpy (readArray,a.readArray,sizeof(string)*arraysize);//Copy the values of bytes from the location pointed at by the souce and destination.
}
ArrayStorage::~ArrayStorage(void)
{
delete[](readArray);//deconstuctor to delete the array.
}
Run Code Online (Sandbox Code Playgroud)
这将是一个更好的方法来复制除memcpy之外的数组:
for (int i = 0 ; i < arraysize ; i ++)
{
readArray[i] = a.readArray[i];
}
Run Code Online (Sandbox Code Playgroud) c# ×7
asp.net ×3
python ×3
c++ ×2
a-star ×1
ajax ×1
arrays ×1
asp.net-mvc ×1
binary-tree ×1
database ×1
dataframe ×1
deep-copy ×1
destructor ×1
dictionary ×1
dll ×1
emoji ×1
exception ×1
intersection ×1
jquery ×1
lambda ×1
linq ×1
list ×1
listbox ×1
path-finding ×1
reflection ×1
set ×1
shallow-copy ×1
signalr ×1
string ×1
substring ×1
tweepy ×1
twitter ×1
websocket ×1