小编Nef*_*pus的帖子

断开图中的所有顶点 - 算法

我正在寻找一种找到最小顶点子集的算法,这样通过从图中移除这个子集(和连接这些顶点的边),所有其他顶点都变得不连接(即图形将没有任何边).

  • 有这样的算法吗?
  • 如果不是:您能否推荐某种启发式来指定顶点.

我对图论有基本了解,所以请原谅任何不正确之处.

algorithm graph

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

Python setuptools:将配置文件分发到操作系统特定的目录

我在使用 Python setuptools 时遇到了先有鸡还是先有蛋的问题。

我想要实现的是将带有我的 pip 包的配置文件(这本身完全可以使用data_files参数 in setup.py)分发到用户配置文件的操作系统特定公共位置(例如~/.config在 Linux 上)。

我发现可以使用appdirs[1] PyPi 包解决操作系统“特异性”问题。还有我的问题 -appdirs在安装我自己的包时不能保证安装,因为它是我的包的依赖项,因此安装在它之后(承诺的鸡或蛋:))

我的setup.py包含这样的东西:

from setuptools import setup
from appdirs import AppDirs
...
setup(
...
    data_files=[
        (AppDirs(name, author).user_config_dir, ['config/myconfig'])
    ],
...
)
Run Code Online (Sandbox Code Playgroud)

这可以在不编写我自己的 setuptools 版本的情况下解决吗(意为典故;))?

[1]:https : //pypi.python.org/pypi/appdirs

python setuptools setup.py

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

c ++用户定义的转换 - 隐式转换

我有一个关于用户定义转换的问题.

class String {
    char* m_data;

public:
    String(): m_data(NULL) {}
    String(const char* cstr): m_data(new char[strlen(cstr)+1]) {
        strcpy(m_data, cstr);
    }
    ~String() {
        delete[] m_data;
    }
    String& operator=(const char* cstr) {
        delete[] m_data;
        m_data = new char[strlen(cstr)+1];
        strcpy(m_data, cstr);
        return *this;
    }
    operator const char*() const { 
        return m_data;
    }
};
Run Code Online (Sandbox Code Playgroud)

虽然这有效:

int main(int argc, char** argv) {
    String a;
    String b;
    a = "aaa";
    b = (const char *)a;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这不是:

int main(int argc, char** argv) {
    String a; …
Run Code Online (Sandbox Code Playgroud)

c++ type-conversion

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

Python - 相当于 Matlab/Octave 键盘功能?

keyboardMatlab/Octave 中有一个函数可以停止执行并控制键盘。

当我有一个长时间运行的脚本并且需要测试一些东西时,它会很有用。由于 Python 是解释性语言,我想它应该是可能的。

Python 中有这样的东西,还是我应该使用更“Pythonic”的东西?:)

python

3
推荐指数
2
解决办法
3712
查看次数

是不是可以不调用父析构函数?

我得到了一个我无法修改的结构.是否可以提供我的析构函数并使用它而不是给定的析构函数?或者可能定义我的结构,然后在需要时进行类型转换?继承也是一种选择,但是没有设法跳过父析构函数的调用.

//Given struct
struct TA {
  ~TA() {
    delete m_L;
    delete m_R;
  }
  TA* m_L;
  TA* m_R;
};

//What i need
struct TB {
  ~TB() {
    if (m_L) m_L->destroy();
    if (m_R) m_R->destroy();
  }
  void destroy() {
    if (!--nRefernece) delete this;
  }
  int nRefernece;
  TB* m_L;
  TB* m_R;
};
Run Code Online (Sandbox Code Playgroud)

c++

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

C++迭代器 - 奇怪的转换

我在使用迭代器时遇到了非常奇怪的错误,我不确定要考虑什么:error: could not convert ‘0’ from ‘int’ to ‘CCarList’

CCarList CRegister::ListCars(const string& name, const string& surname) const {
    auto ownerIt = findOwner(name, surname);
    if (ownerIt == m_owners.end()) return 0; //Error is on this line
    //...
}
Run Code Online (Sandbox Code Playgroud)

findOwner:

vector<TOwner*>::const_iterator CRegister::findOwner(const string& name, 
                                                  const string& surname) const 
{
    return lower_bound(m_owners.begin(), m_owners.end(), TOwner(name, surname), 
        [](const TOwner* a, const TOwner& b){return (*a) < b;});
}
Run Code Online (Sandbox Code Playgroud)

m_ownersvector<TOwner*>(TOwner是struct.)

CCarList:

class CCarList {
    vector<TCar*>::iterator m_it;
    const vector<TCar*>::iterator m_end;
public:
    CCarList(vector<TCar*>::iterator it, const vector<TCar*>::iterator …
Run Code Online (Sandbox Code Playgroud)

c++ iterator vector

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

Maven构建错误-无法执行目标org.apache.maven.plugins:maven-assembly-plugin:2.5.5

我正在尝试使用Maven构建项目。不幸的是我没有Maven的经验,所以我有点无助。它很可能是由riak子模块引起的。这是带有代码的github回购代码:YCSB

我的系统:

Apache Maven 3.2.2 (NON-CANONICAL_2015-04-01T06:56:20_mockbuild; 2015-04-01T08:56:20+02:00)
Maven home: /usr/share/maven
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-4.b16.fc21.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.1.5-100.fc21.x86_64", arch: "amd64", family: "unix"
Run Code Online (Sandbox Code Playgroud)

Maven堆栈跟踪:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.5.5:single (default) on project ycsb: Failed to create assembly: Artifact: com.yahoo.ycsb:riak-binding:jar:0.3.1-RC1-SNAPSHOT (included by module) does not have an artifact with a file. Please ensure the package phase is run before the assembly is generated. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed …
Run Code Online (Sandbox Code Playgroud)

java build maven

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