小编Set*_*sak的帖子

GA中的排名选择?

我已经实施Roulette wheel selectionGA.

   TotalFitness=sum(Fitness);
    ProbSelection=zeros(PopLength,1);
    CumProb=zeros(PopLength,1);

    for i=1:PopLength
        ProbSelection(i)=Fitness(i)/TotalFitness;
        if i==1
            CumProb(i)=ProbSelection(i);
        else
            CumProb(i)=CumProb(i-1)+ProbSelection(i);
        end
    end

    SelectInd=rand(PopLength,1);

    for i=1:PopLength
        flag=0;
        for j=1:PopLength
            if(CumProb(j)<SelectInd(i) && CumProb(j+1)>=SelectInd(i))
                SelectedPop(i,1:IndLength)=CurrentPop(j+1,1:IndLength);
                flag=1;
                break;
            end
        end
        if(flag==0)
            SelectedPop(i,1:IndLength)=CurrentPop(1,1:IndLength);
        end
    end
Run Code Online (Sandbox Code Playgroud)

现在我是想实现rank selectionGA.我了解到:

  • 排名选择首先对人群进行排名,然后每个染色体从该排名中获得适应性.

  • 最差的将是健身1,第二差2等等,最好的将具有适应度N(人口中的染色体数量).

我看到了这些link1link2,我理解的是:

  1. 首先,我将对人口的健身价值进行排序.

  2. 然后,如果人口数量是10,那么我将给予人口选择的概率,如0.1,0.2,0.3,...,1.0.

  3. 然后我将计算累积健身像轮盘赌轮.
  4. 接下来的步骤与轮盘赌轮相同.

我的实施:

  NewFitness=sort(Fitness);
    NewPop=round(rand(PopLength,IndLength));

    for i=1:PopLength
        for j=1:PopLength
            if(NewFitness(i)==Fitness(j))
                NewPop(i,1:IndLength)=CurrentPop(j,1:IndLength);
                break;
            end
        end
    end
    CurrentPop=NewPop;

    ProbSelection=zeros(PopLength,1);
    CumProb=zeros(PopLength,1);

    for i=1:PopLength
        ProbSelection(i)=i/PopLength;
        if i==1
            CumProb(i)=ProbSelection(i);
        else
            CumProb(i)=CumProb(i-1)+ProbSelection(i);
        end …
Run Code Online (Sandbox Code Playgroud)

matlab selection genetic-algorithm

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

如何在输入字段开头的圆圈内放置一个图标?

我试图在圆圈内放置一个图标,该圆圈将放置在输入字段的开头,如下所示:

在此输入图像描述

我正在尝试使用以下代码实现此目的ionic:

//在.html中

<ion-row>
  <ion-item>
    <ion-label> <ion-icon name="person"></ion-icon></ion-label>
    <ion-input clearInput type="text"></ion-input>
  </ion-item>
</ion-row>
Run Code Online (Sandbox Code Playgroud)

//在.scss中

ion-item {
  border-radius: 23px;
  padding-left: 0;
}

ion-label {
    border-radius: 23px;
    border: 2px solid red;
    width: 12%;
    height: 100%;
}
Run Code Online (Sandbox Code Playgroud)

但我只能在下面实现:

在此输入图像描述

任何人都可以帮助我吗?

html css ionic-framework

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

从android中的Service调用BroadCastReceiver来更新Fragment中的UI?

我想更新UI一个fragmentfrom service.我正在使用GCM发送消息.我有这个类GCM:

    public class GcmIntentService extends IntentService {

        public GcmIntentService() {
            super("GcmIntentService");
        }

        @Override
        protected void onHandleIntent(Intent intent) {
            Bundle extras = intent.getExtras();
            GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
            // The getMessageType() intent parameter must be the intent you received
            // in your BroadcastReceiver.
            String messageType = gcm.getMessageType(intent);

            if (extras != null && !extras.isEmpty()) {  // has effect of unparcelling Bundle
                // Since we're not using two way messaging, this is all we …
Run Code Online (Sandbox Code Playgroud)

android broadcastreceiver android-service android-fragments google-cloud-messaging

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

两个整数的幂

我正在尝试解决有关两个整数的幂的问题。问题描述如下:

给定一个适合 32 位有符号整数的正整数,找出它是否可以表示为 A^P,其中 P > 1 和 A > 0。A 和 P 都应该是整数。
示例:
输入:n = 8
输出:true
8 可以表示为 2^3

输入:n = 49
输出:true
49 可以表示为 7^2

现在,我按照以下方法来解决问题。

int Solution::isPower(int A) {
    if(A == 1)
    {
        return true;
    }
    
    for(int x = 2; x <= sqrt(A); x++)
    {
        unsigned long long product = x * x;
        
        while(product <= A && product > 0)
        {
            if(product == A)
            {
                return true;
            }
            
            product = product * x;
        } …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm logarithm

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

如何在tinymce中合并变更事件?

我正在尝试在我的项目中使用angular2-tinymce库。我已成功将tinymce集成到我的模块中。但是当tinymce编辑器中发生任何更改时,我无法触发更改事件的任何回调。

// in add-progress-note.module.ts file
@NgModule({
  declarations: [
    AddProgressNotePage,
  ],
  imports: [
    IonicPageModule.forChild(AddProgressNotePage),
    TinymceModule.withConfig({
      menubar: false,
      plugins: ['textcolor'],
      toolbar: 'forecolor',
      resize: false,
      statusbar: false
    })
  ]
})

// in add-progress-note.html file           
<ion-row class="note-editor" id="noteArea">
            <app-tinymce class="note-input-textarea" [(ngModel)]='noteText' (change)="onChangeNote()"></app-tinymce>
</ion-row>

// in add-progress-note.ts file
  onChangeNote(): void {
    console.log(this.noteText);
  }
Run Code Online (Sandbox Code Playgroud)

我的 onChangeNote 没有触发。

如何为tinymce编辑器中的任何更改事件触发回调事件?

tinymce ionic-framework angular

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

如何将线性渐变应用于圆的边界?

我试图在标签的圆圈中实现线性渐变,如下图所示ionic

在此处输入图片说明

起初,我使用以下代码在输入开始处画了一个圆圈:

// 在 .html 中

<ion-item class="wrapper border-radius-23">
  <ion-label class="email-label">
    <ion-icon name="person" class="text-red"></ion-icon>
  </ion-label>
  <ion-input clearInput type="text" placeholder="Email" class="user-email-input"></ion-input>
</ion-item>
Run Code Online (Sandbox Code Playgroud)

// 在 .scss 文件中

  .user-email-input {
    height: 46px;
    width: 100%;
    display: block;
    border-radius: 23px;
    box-sizing: border-box;
    padding-left: 50px;
    outline: none;
  }

  .email-label {
    border-radius: 50%;
    border: 2px solid red;
    position: absolute;
    top: -13px;
    left: 0;
    width: 46px;
    height: 46px;
    z-index: 9;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
  }
Run Code Online (Sandbox Code Playgroud)

并实现如下:

在此处输入图片说明

现在,当我尝试在圆圈中应用渐变时,我只能实现如下:

在此处输入图片说明

我更改了电子邮件标签的 css,如下所示:

.email-label {
        border-image: …
Run Code Online (Sandbox Code Playgroud)

html css ionic-framework

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

关于 - >在c ++中的困惑?

我知道那-->不是运营商.它实际上是两个独立的运算符-->.它与下面的操作相同.

while( (x--) > 0 )
Run Code Online (Sandbox Code Playgroud)

现在我运行了两个程序,但它在我身上引起了一些困惑.

第一个计划:

int main(void)
{
    int x = 10;
    while(----x>0)
   {
     cout<<x<<endl;
   }
}
Run Code Online (Sandbox Code Playgroud)

产出: 8 6 4 2

第二个程序:

int main(void)
{
    int x = 10;
    while(x---->0)
   {
     cout<<x<<endl;
   }
}
Run Code Online (Sandbox Code Playgroud)

我有编译错误:

lvalue需要作为递减操作数

其实这里发生了什么?为什么第一个程序运行成功而不是第二个程序?

c++ decrement

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