问题列表 - 第6416页

什么是"Hello World!" 遗传算法的好处是什么?

我发现这个非常酷的C++示例,字面意思是"Hello World!" 遗传算法.

我决定用C#重新编写整个代码,就是结果.

现在我问自己:从一群随机字符串开始生成目标字符串是否有任何实际应用?

编辑:我在Twitter上的好友刚刚发推文说"对转录类型的东西很有用,比如翻译.不一定是猴子的".我希望我有一个线索.

c# c++ genetic-algorithm

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

传递函数对象:错误

传递函数对象的以下小程序有什么问题?

#include <iostream>
#include <functional>

void foo(const std::unary_function<const std::string&, void>& fct) {
  const std::string str = "test";
  fct(str); // error
}

class MyFct : public std::unary_function<const std::string&, void> {
public:
  void operator()(const std::string& str) const {
    std::cout << str << std::endl;
  }
};

int main(int argc, char** argv){
  MyFct f;
  foo(f);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我在第6行收到以下错误:

 no match for call to 
`(const std::unary_function<const std::string&, void>) (const std::string&)'
Run Code Online (Sandbox Code Playgroud)

c++ functional-programming unary-function

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

凹面多边形绘图

要使用OpenGL绘制复杂的凹多边形,最好将其镶嵌成三角形,还是使用模板缓冲区?我猜测单个帧的模板缓冲区会更快,但如果多边形不变,则三角测量对于多个帧会更好.但是,我还没有尝试过,所以我不知道.

opengl polygon concave triangulation stencil-buffer

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

如何使用远程控制与Linux C或C++应用程序进行交互?

我想捕捉电视遥控器的输入,并检测我的应用程序中按下了哪些按钮.操作系统是Linux(Windows的答案对我来说不会有太大用处,但可能对其他人有用).我正在使用C++,但C代码也适用于我.

我想以类似于此的方式使用代码:

if (remoteControl.buttonPressed(PLAY_BUTTON))
{
    fooBar.doSomethingFun();
}
Run Code Online (Sandbox Code Playgroud)

另外,我在想可能有一个我可以使用的通用库,它可以用于所有遥控器,还是我必须做一些非常低级的编码?

c c++

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

如何(替换|创建)rails 2.0迁移的枚举字段?

我想在我正在进行的sone迁移中创建一个枚举字段,我尝试在谷歌搜索,但我无法在迁移中找到方法

我发现的唯一的事情是

  t.column :status, :enum, :limit => [:accepted, :cancelled, :pending]
Run Code Online (Sandbox Code Playgroud)

但看起来上面的代码只在rails 1.xxx上运行,因为我正在运行rails 2.0

这就是我尝试但它失败了

class CreatePayments < ActiveRecord::Migration
  def self.up
    create_table :payments do |t|
      t.string :concept
      t.integer :user_id
      t.text :notes
      t.enum :status, :limit => [:accepted, :cancelled, :pending]

      t.timestamps
    end
  end

  def self.down
    drop_table :payments
  end
end
Run Code Online (Sandbox Code Playgroud)

那么,如果不允许,您认为什么是一个好的解决方案?只是一个文本字段,并从模型验证?

ruby migration ruby-on-rails

29
推荐指数
4
解决办法
2万
查看次数

如何在Linux或Windows中编译OS X?

我想将我的C/C++应用程序移植到OS X.

我没有Mac,但我有Linux和Windows.这有什么工具吗?

c c++ macos cross-compiling

68
推荐指数
5
解决办法
7万
查看次数

如何从actionscript中读取全局javascript变量

鉴于我的网页上有一个名为myVar的全局javascript变量,如何使用javascript从我的flash影片中访问变量myVar的值?

我看到很多使用外部接口的例子,以便从actionscript执行javascript,但是我无法找到使用actionscript将值返回到flash影片的示例.

提前致谢.我希望我的问题很清楚.

javascript actionscript externalinterface

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

如何在Java中为Android设置HttpResponse超时

我创建了以下用于检查连接状态的函数:

private void checkConnectionStatus() {
    HttpClient httpClient = new DefaultHttpClient();

    try {
      String url = "http://xxx.xxx.xxx.xxx:8000/GaitLink/"
                   + strSessionString + "/ConnectionStatus";
      Log.d("phobos", "performing get " + url);
      HttpGet method = new HttpGet(new URI(url));
      HttpResponse response = httpClient.execute(method);

      if (response != null) {
        String result = getResponse(response.getEntity());
        ...
Run Code Online (Sandbox Code Playgroud)

当我关闭服务器进行测试时,执行会等待很长时间

HttpResponse response = httpClient.execute(method);
Run Code Online (Sandbox Code Playgroud)

有谁知道如何设置超时以避免等待太久?

谢谢!

java android timeout httpresponse

332
推荐指数
5
解决办法
19万
查看次数

为什么不subprocess.Popen(...)总是返回?

我希望这是一个简单的python问题.

当我在python解释器中尝试以下内容时:

>>> import process
>>> def test(cmd):
...   p = subprocess.Popen(cmd)
...
>>> test(['ls', '-l'])
Run Code Online (Sandbox Code Playgroud)

它将运行ls -l,但我需要点击"返回"以获得新的>>>提示.

但是,当我尝试以下内容时:

>>> import process
>>> def test(cmd):
...   p = subprocess.Popen(cmd)
...   p.wait()
...
>>> test(['ls', '-l'])
Run Code Online (Sandbox Code Playgroud)

然后ls -l将立即运行>>>提示符运行.

另一个变种:

>>> import process
>>> def test(cmd):
...   p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
...
>>> test(['ls', '-l'])
Run Code Online (Sandbox Code Playgroud)

这将立即给我一个新的提示.

最后一个例子最接近我想要的.我的目标是启动一个子进程,等待它完成,然后通过引用在我的父进程中使用它的stdout,p.stdout同时让stderr只是打印到任何地方.

现在在我的实际应用程序中,最后一个版本只挂起: p = subprocess.Popen(cmd, stdout=subprocess.PIPE)有或没有p.wait().

谢谢,

查理

python subprocess

6
推荐指数
2
解决办法
9826
查看次数

理解Python类实例

我正在研究一个使用python类的问题,并且有一个构造函数来给出一个die的边数和一个用于根据边数返回的随机数掷出die的函数.我意识到代码是非常基本的,但是我很难理解如何总结三个不同侧面的掷骰子.由于变量正在传递函数实例,因此获取该值的最佳方法是什么?这就是我所拥有的.

*澄清......我可以将roll1.roll_dice()的总数加起来,但我必须单独显示每个掷骰子,然后显示三个骰子的总数.我可以做其中任何一个但不是两个.

class Die():

        def __init__(self, s = 6):
            self.sides = s
        def roll_die(self):
            x = random.randint(1,self.sides)
            return x

        roll1 = Die()   #Rolling die 1 with the default side of 6
        roll2 = Die(4)  #Rolling die 2 with 4 sides
        roll3 = Die(12) #Rolling die 3 with 12 sides

        print roll1.roll_die()  
        print roll2.roll_die()
        print roll3.roll_die()
Run Code Online (Sandbox Code Playgroud)

python sum class

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