小编dmd*_*dmd的帖子

在图表中查找访问某些节点的最短路径

我有一个带有大约100个节点和大约200个边的无向图.一个节点标记为"开始",一个节点标记为"结束",并且大约有十几个标记为"必须通过".

我需要找到通过此图表的最短路径,该路径从'start'开始,在'end'结束,并通过所有'mustpass'节点(以任何顺序).

(http://3e.org/local/maize-graph.png/http://3e.org/local/maize-graph.dot.txt是有问题的图表 - 它代表宾夕法尼亚州兰开斯特的一个玉米迷宫)

algorithm graph-theory

72
推荐指数
6
解决办法
7万
查看次数

从OS X上的Chrome获取最前端选项卡的URL?

有没有办法对Chrome执行此操作?

tell application "Google Chrome"
 return URL of front document as string
end tell
Run Code Online (Sandbox Code Playgroud)

......不起作用.

applescript google-chrome

12
推荐指数
3
解决办法
9135
查看次数

如何在reStructuredText/Sphinx中创建浮动数字?

我想要一个带有文字的图形.

这就是我所说的:

Installation of Optional Accessories
====================================

.. warning:: Never plug in or unplug a Hand Robot or a Grasp Sensor while the robot is turned on, as the system will not function properly and damage to the robot could occur.

Installing a Hand Robot
-----------------------

.. _`fig-attach-hand-robot`:
.. figure:: attach-hand-robot.*
  :scale: 40%
  :align: right

  Attach Hand Robot

Make sure the robot is turned off as described in the section :ref:`turn-off-robot`. 

Take the hand robot out of the grounded bin …
Run Code Online (Sandbox Code Playgroud)

restructuredtext python-sphinx

8
推荐指数
3
解决办法
2490
查看次数

使用二分(在Python中)查找列表中f(x)更改的位置

推理:我试图在Python中实现类似的东西git bisect,但基本上是一个目录列表.

我有一个(长)版本号列表,如下所示: ['1.0', '1.14', '2.3', '3.1', '4']

我有一个函数works(),它取一个版本号,并返回一个值.

[works(x) for x in my_list]看起来像['foo', 'foo', 'foo', 'bar', 'bar'] ...... : 但是跑步works()非常昂贵.

我想做一些可以找到变化边界的二等分.

python git-bisect bisection bisect

8
推荐指数
1
解决办法
218
查看次数

为什么全局变量不能像导入时那样工作?

在文件中foo.py我有这个:

d = {}
d['x'] = 0
x = 0

def foo():
    global d
    global x
    d['x'] = 1
    x = 1
Run Code Online (Sandbox Code Playgroud)

然后在翻译中:

>>> from foo import *
>>> d['x']
0
>>> x
0
>>> foo()
>>> d['x']
1
>>> x
0
Run Code Online (Sandbox Code Playgroud)

我期待这个:

>>> x
1
Run Code Online (Sandbox Code Playgroud)

我不明白的是什么?

python variables scope

6
推荐指数
1
解决办法
46
查看次数

如何在Python中使用JSONDecoder?仅获取内部字典进行解码

我有一个 JSONEncoder 和 JSONDecoder:

class SimpleTargetJSONEncoder(json.JSONEncoder):
    """
    converts a SimpleTarget to a Dict so it can be JSONified
    """

    def default(self, o):
        if isinstance(o, SimpleTargetItem):
            return {
                'x': o.x(),
                'y': o.y(),
                'status': o.status,
                'imageSet': o.imageSet}


class SimpleTargetJSONDecoder(json.JSONDecoder):
    def __init__(self):
        json.JSONDecoder.__init__(self, object_hook=self.dict_to_object)

    def dict_to_object(self, d):
        t = SimpleTargetItem(imageSet=d['imageSet'])
        t.setX(d['x'])
        t.setY(d['y'])
        return t
Run Code Online (Sandbox Code Playgroud)

编码器写出如下文件:

[
    {
        "y": 2514.0, 
        "x": 2399.0, 
        "status": "default", 
        "imageSet": {
            "default": ":/images/blue-circle.png", 
            "active": ":/images/green-circle.png", 
            "removed": ":/images/black-circle.png", 
        }
    }, 
    {
        "y": 2360.0, 
        "x": 2404.0, 
        "status": "default", 
        "imageSet": {
            "default": …
Run Code Online (Sandbox Code Playgroud)

python json

4
推荐指数
1
解决办法
6560
查看次数

为什么菜单没有添加?

我在这里显然遗漏了一些东西; 为什么在这个小示例应用程序中没有添加"文件"菜单?

import sys
from PySide.QtGui import *

class Window(QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        self.setWindowTitle('Test')
        layout = QHBoxLayout()
        self.widget = QWidget()
        self.widget.setLayout(layout)
        self.setCentralWidget(self.widget)
        self.exitAction = QAction('Exit', self, shortcut=QKeySequence.Quit, triggered=self.close)
        self.fileMenu = self.menuBar().addMenu('File')
        self.fileMenu.addAction(self.exitAction)

app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

编辑:

好吧,看起来这实际上是一个unicode问题.这是另一个示例应用程序:

from __future__ import unicode_literals, print_function, division
import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Window(QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        self.dummyAction = QAction(self.tr('dummy'), self, triggered=self.dummy)
        self.gameMenu = self.menuBar().addMenu(self.tr('ddddummy'))
        print (self.tr('dummy'))
        self.gameMenu.addAction(self.dummyAction)
        layout = QHBoxLayout()
        self.widget …
Run Code Online (Sandbox Code Playgroud)

qt pyqt pyside qmainwindow

4
推荐指数
1
解决办法
1667
查看次数

Mono.Options:检查是否给出了无效选项

我定义了

var p = new OptionSet () {
 // various options defined
};
Run Code Online (Sandbox Code Playgroud)

然后我

p.Parse(args)
Run Code Online (Sandbox Code Playgroud)

如果我打电话给我的程序

myprogram --thisOptionIsNotDefined
Run Code Online (Sandbox Code Playgroud)

我想显示一条帮助信息,而不是继续.但是Parse()在遇到无效选项时不会抛出OptionException.我该怎么办?

c# mono

2
推荐指数
1
解决办法
544
查看次数

如何在Heroku或类似的程序上运行此应用程序?

我想得到这个应用程序:https: //github.com/lysol/typeto.me/

在Heroku(或类似的服务)上运行.

我需要遵循哪些步骤?我很难理解放在哪里.

我已经知道我需要做这样的事情:
我可以在Heroku中运行coffeescript吗? 对于coffeescript的东西.

heroku paas node.js dotcloud

1
推荐指数
1
解决办法
245
查看次数