Android background processing with Handlers, AsyncTask and Loaders - Tutorial

本文档详细介绍了Android应用程序中并发处理的使用方法,包括线程、Handler、AsyncTask等组件的应用场景及实现方式,并探讨了如何在配置更改时保持状态。
Android Threads, Handlers AsyncTask. This tutorial describes the usage of asynchronous processing in Android applications. It also covers how to handle the application life cycle together with threads. It is based on Android Studio.

1. Background processing in Android

1.1. Why using concurrency?

By default, application code runs in the main thread. Every statement is therefore executed in sequence. If you perform a long lasting operation, the application blocks until the corresponding operation has finished.

To provide a good user experience all potentially slow running operations in an Android application should run asynchronously. This can be archived via concurrency constructs of the Java language or of the Android framework. Potentially slow operations are for example network, file and database access and complex calculations.

  Android enforces a worst case reaction time of applications. If an activity does not react within 5 seconds to user input, the Android system displays an Application not responding (ANR) dialog. From this dialog the user can choose to stop the application.

1.2. Main thread

Android modifies the user interface and handles input events from one single thread, called the main thread. Android collects all events in this thread in a queue and processes this queue with an instance of the Looper class.

Message Queue in Android with Looper

1.3. Threading in Android

Android supports the usage of the Thread class to perform asynchronous processing. Android also supplies thejava.util.concurrent package to perform something in the background. For example, by using the ThreadPools andExecutor classes.

If you need to update the user interface from a new Thread, you need to synchronize with the main thread. Because of this restrictions, Android developer typically use Android specific code constructs.

Android provides additional constructs to handle concurrently in comparison with standard Java.

You can use the android.os.Handler class or the AsyncTasks classes. More sophisticated approaches are based on theLoader class, retained fragments and services.

1.4. Providing feedback to a long running operation

If you are performing a long running operation it is good practice to provide feedback to the user about the running operation.

You can provide progress feedback via the action bar for example via an action view. Alternatively you can use aProgressBar in your layout which you set to visible and update it during a long running operation. Non blocking feedback is preferred so that the user can continue to interact with the applicatoin.

 

Avoid using the blocking ProgressBar dialog or similar approaches if possible. Prefer providing inline feedback to that your user interface stays responsive.

2. Handler

2.1. Purpose of the Handler class

Handler object registers itself with the thread in which it is created. It provides a channel to send data to this thread. For example, if you create a new Handler instance in the onCreate() method of your activity, it can be used to post data to the main thread. The data which can be posted via the Handler class can be an instance of the Message or theRunnable class. A Handler is particular useful if you have want to post multiple times data to the main thread.

2.2. Creating and reusing instances of Handlers

To implement a handler subclass it and override the handleMessage() method to process messages. You can post messages to it via the sendMessage(Message) or via the sendEmptyMessage() method. Use the post() method to send a Runnable to it.

To avoid object creation, you can also reuse the existing Handler object of your activity.

// Reuse existing handler if you don't
// have to override the message processing
handler = getWindow().getDecorView().getHandler();

The View class allows you to post objects of type Runnable via the post() method.

2.3. Example

The following code demonstrates the usage of an handler from a view. Assume your activity uses the following layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:max="10"
        android:padding="4dip" >
    </ProgressBar>

         <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" >
      </TextView>
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="startProgress"
        android:text="Start Progress" >
    </Button>

</LinearLayout>

With the following code the ProgressBar get updated once the users presses the Button.

package de.vogella.android.handler;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ProgressTestActivity extends Activity {
        private ProgressBar progress;
        private TextView text;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                progress = (ProgressBar) findViewById(R.id.progressBar1);
                text = (TextView) findViewById(R.id.textView1);

        }

        public void startProgress(View view) {
                // do something long
                Runnable runnable = new Runnable() {
                        @Override
                        public void run() {
                                for (int i = 0; i <= 10; i++) {
                                        final int value = i;
                                         doFakeWork();
                                        progress.post(new Runnable() {
                                                @Override
                                                public void run() {
                                                        text.setText("Updating");
                                                        progress.setProgress(value);
                                                }
                                        });
                                }
                        }
                };
                new Thread(runnable).start();
        }

        // Simulating something timeconsuming
        private void doFakeWork() {
                try {
                        Thread.sleep(2000);
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
        }

}

3. AsyncTask

3.1. Purpose of the AsyncTask class

The AsyncTask class allows to run instructions in the background and to synchronize again with the main thread. It also reporting progress of the running tasks. AsyncTasks should be used for short background operations which need to update the user interface. .

3.2. Using the AsyncTask class

To use AsyncTask you must subclass it. AsyncTask uses generics and varargs. The parameters are the followingAsyncTask <TypeOfVarArgParams , ProgressValue , ResultValue>.

An AsyncTask is started via the execute() method. This execute() method calls the doInBackground() and theonPostExecute() method.

TypeOfVarArgParams is passed into the doInBackground() method as input. ProgressValue is used for progress information and ResultValue must be returned from doInBackground() method. This parameter is passed toonPostExecute() as a parameter.

The doInBackground() method contains the coding instruction which should be performed in a background thread. This method runs automatically in a separate Thread.

The onPostExecute() method synchronizes itself again with the user interface thread and allows it to be updated. This method is called by the framework once the doInBackground() method finishes.

3.3. Parallel execution of several AsyncTasks

Android executes AsyncTask tasks before Android 1.6 and again as of Android 3.0 in sequence by default. You can tell Android to run it in parallel with the usage of the executeOnExecutor() method specifyingAsyncTask.THREAD_POOL_EXECUTOR as first parameter.

The following code snippet demonstrates that.

// ImageLoader extends AsyncTask
ImageLoader imageLoader = new ImageLoader( imageView );

// Execute in parallel
imageLoader.executeOnExecutor( AsyncTask.THREAD_POOL_EXECUTOR, "http://url.com/image.png" );
 

The AsyncTask does not handle configuration changes automatically, i.e. if the activity is recreated. The programmer has to handle that in his coding. A common solution to this is to declare the AsyncTask in a retained headless fragment.

3.4. Example: AsyncTask

The following code demonstrates how to use the AsyncTask class to download the content of a webpage.

Create a new Android project called de.vogella.android.asynctask with an activity called ReadWebpageAsyncTask. Add theandroid.permission.INTERNET permission to your AndroidManifest.xml file.

Create the following layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/readWebpage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="onClick"
        android:text="Load Webpage" >
    </Button>

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Placeholder" >
    </TextView>

</LinearLayout>

Change your activity to the following:

package de.vogella.android.asynctask;

// imports cut out for brevity

public class ReadWebpageAsyncTask extends Activity {
        private TextView textView;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                textView = (TextView) findViewById(R.id.TextView01);
        }

        private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
                @Override
                protected String doInBackground(String... urls) {
                        // we use the OkHttp library from https://github.com/square/okhttp
                        OkHttpClient client = new OkHttpClient();
                        Request request =
                                        new Request.Builder()
                                        .url(urls[0])
                                        .build();
                                 Response response = client.newCall(request).execute();
                                 if (response.isSuccessful()) {
                                         return response.body().string();
                                 }
                        }
                        return "Download failed";
                }

                @Override
                protected void onPostExecute(String result) {
                        textView.setText(result);
                }
        }

        public void onClick(View view) {
                DownloadWebPageTask task = new DownloadWebPageTask();
                task.execute(new String[] { "http://www.vogella.com/index.html" });

        }
}

Run your application and press the button. The defined webpage is read in the background. Once this process is done your TextView is updated.

4. Background processing and lifecycle handling

4.1. Retaining state during configuration changes

One challenge in using threads is to consider the lifecycle of the application. The Android system may kill your activity or trigger a configuration change which will also restart your activity.

You also need to handle open dialogs, as dialogs are always connected to the activity which created them. In case the activity gets restarted and you access an existing dialog you receive a View not attached to window manager exception.

To save an object you can use the onRetainNonConfigurationInstance() method. This method allows you to save one object if the activity will be soon restarted.

To retrieve this object you can use the getLastNonConfigurationInstance() method. This way can you can save an object, e.g. a running thread, even if the activity is restarted.

getLastNonConfigurationInstance() returns null if the activity is started the first time or if it has been finished via the finish() method.

onRetainNonConfigurationInstance() is deprecated as of API 13. It is recommended that you use fragments and thesetRetainInstance() method to retain data over configuration changes.

4.2. Using the application object to store objects

If more than one object should be stored across activities and configuration changes, you can implement an Applicationclass for your Android application.

To use your application class assign the classname to the android:name attribute of your application.

<application android:icon="@drawable/icon" android:label="@string/app_name"
        android:name="MyApplicationClass">
         <activity android:name=".ThreadsLifecycleActivity"
                android:label="@string/app_name">
                 <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
        </activity>
</application>

The application class is automatically created by the Android runtime and is available unless the whole application process is terminated.

This class can be used to access objects which should be cross activities or available for the whole application lifecycle. In the onCreate() method you can create objects and make them available via public fields or getter methods.

The onTerminate() method in the application class is only used for testing. If Android terminates the process in which your application is running all allocated resources are automatically released.

You can access the Application via the getApplication() method in your activity.

5. Fragments and background processing

5.1. Retain instance during configuration changes

You can use fragments without user interface and retain them between configuration changes via a call to theirsetRetainInstance() method.

This way your Thread or AsyncTask is retained during configuration changes. This allows you to perform background processing without explicitly considering the lifecycle of your activity.

5.2. Headless fragments

If you perform background processing you can dynamically attached a headless fragment to your application and callsetRetainInstance() to true. This fragment is retained during configuration changes and you can perform asynchronous processing in it.

6. Loader

6.1. Purpose of the Loader class

The Loader class allows you to load data asynchronously in an activity or fragment. They can monitor the source of the data and deliver new results when the content changes. They also persist data between configuration changes.

The data can be cached by the Loader and this caching can survive configuration changes. Loaders have been introduced in Android 3.0 and are part of the compatibility layer for Android versions as of 1.6.

6.2. Implementing a Loader

You can use the abstract AsyncTaskLoader class as the basis for your custom Loader implementations.

The LoaderManager of an activity or fragment manages one or more Loader instances. The creation of a Loader is done via the following method call.

# start a new loader or re-connect to existing one
getLoaderManager().initLoader(0, null, this);

The first parameter is a unique ID which can be used by the callback class to identify the Loader. The second parameter is a bundle which can be given to the callback class for more information.

The third parameter of initLoader() is the class which is called once the initialization has been started (callback class). This class must implement the LoaderManager.LoaderCallbacks interface. It is common practice that an activity or the fragment which uses a Loader implements the LoaderManager.LoaderCallbacks interface.

The Loader is not directly created by the getLoaderManager().initLoader() method call, but must be created by the callback class in the onCreateLoader() method.

Once the Loader has finished reading data asynchronously, the onLoadFinished() method of the callback class is called. Here you can update your user interface.

6.3. SQLite database and CursorLoader

Android provides a Loader default implementation to handle SQlite database connections, the CursorLoader class.

For a ContentProvider based on an SQLite database you would typically use the CursorLoader class. This Loaderperforms the database query in a background thread so that the application is not blocked.

The CursorLoader class is the replacement for Activity-managed cursors which are deprecated now.

If the Cursor becomes invalid, the onLoaderReset() method is called on the callback class.

7. Exercise: Custom loader for preferences

7.1. Implementation

In the following your create a custom loader implementation for managing preferences. On every load the value of the preference is increased.

Create a project called com.vogella.android.loader.preferences with an activity called MainActivity.

Create the following class as custom AsyncTaskLoader implementation for managing shared preferences.

package com.vogella.android.loader.preferences;

import android.content.AsyncTaskLoader;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class SharedPreferencesLoader extends AsyncTaskLoader<SharedPreferences>
                implements SharedPreferences.OnSharedPreferenceChangeListener {
        private SharedPreferences prefs = null;

        public static void persist(final SharedPreferences.Editor editor) {
                editor.apply();
        }

        public SharedPreferencesLoader(Context context) {
                super(context);
        }

        // Load the data asynchronously
        @Override
        public SharedPreferences loadInBackground() {
                prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
                prefs.registerOnSharedPreferenceChangeListener(this);
                return (prefs);
        }

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                        String key) {
                // notify loader that content has changed
                onContentChanged();
        }

        /**
         * starts the loading of the data
         * once result is ready the onLoadFinished method is called
         * in the main thread. It loader was started earlier the result
         * is return directly

         * method must be called from main thread.
         */
        @Override
        protected void onStartLoading() {
                if (prefs != null) {
                        deliverResult(prefs);
                }

                if (takeContentChanged() || prefs == null) {
                        forceLoad();
                }
        }
}

The following example code demonstrates the usage of this loader in an activity.

package com.vogella.android.loader.preferences;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.LoaderManager;
import android.content.Loader;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity implements
                LoaderManager.LoaderCallbacks<SharedPreferences> {
        private static final String KEY = "prefs";
        private TextView textView;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                textView = (TextView) findViewById(R.id.prefs);
                getLoaderManager().initLoader(0, null, this);

        }

        @Override
        public Loader<SharedPreferences> onCreateLoader(int id, Bundle args) {
                return (new SharedPreferencesLoader(this));
        }

        @SuppressLint("CommitPrefEdits")
        @Override
        public void onLoadFinished(Loader<SharedPreferences> loader,
                        SharedPreferences prefs) {
                int value = prefs.getInt(KEY, 0);
                value += 1;
                textView.setText(String.valueOf(value));
                // update value
                SharedPreferences.Editor editor = prefs.edit();
                editor.putInt(KEY, value);
                SharedPreferencesLoader.persist(editor);
        }

        @Override
        public void onLoaderReset(Loader<SharedPreferences> loader) {
                // NOT used
        }
}

7.2. Test

The LoaderManager call onLoadFinished() in your activity automatically after a configuration change. Run the application and ensure that the value stored in the shared preferences is increased at every configuration change.

8. Usage of services

You can also use Android services to perform background tasks. Seehttp://www.vogella.com/tutorials/AndroidServices/article.html - Android service tutorial for details.

9. Exercise: activity lifecycle and threads

The following example will download an image from the Internet in a thread and displays a dialog until the download is done. We will make sure that the thread is preserved even if the activity is restarted and that the dialog is correctly displayed and closed.

For this example create a new Android project called de.vogella.android.threadslifecycle with the Activity calledThreadsLifecycleActivity. Also add the permission to use the Internet to your AndroidManifest.xml file.

Your AndroidManifest.xml file should look like the following.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.vogella.android.threadslifecycle"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".ThreadsLifecycleActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Change the layout main.xml to the following.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="downloadPicture"
            android:text="Click to start download" >
        </Button>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="resetPicture"
            android:text="Reset Picture" >
        </Button>
    </LinearLayout>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/icon" >
    </ImageView>

</LinearLayout>

Now adjust your activity. In this activity the thread is saved and the dialog is closed if the activity is destroyed.

package de.vogella.android.threadslifecycle;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;

public class ThreadsLifecycleActivity extends Activity {
        // Static so that the thread access the latest attribute
        private static ProgressDialog dialog;
        private static Bitmap downloadBitmap;
        private static Handler handler;
        private ImageView imageView;
        private Thread downloadThread;

        /** Called when the activity is first created. */

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                // create a handler to update the UI
                handler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                                imageView.setImageBitmap(downloadBitmap);
                                dialog.dismiss();
                        }

                };
                // get the latest imageView after restart of the application
                imageView = (ImageView) findViewById(R.id.imageView1);
                Context context = imageView.getContext();
                System.out.println(context);
                // Did we already download the image?
                if (downloadBitmap != null) {
                        imageView.setImageBitmap(downloadBitmap);
                }
                // check if the thread is already running
                downloadThread = (Thread) getLastNonConfigurationInstance();
                if (downloadThread != null && downloadThread.isAlive()) {
                        dialog = ProgressDialog.show(this, "Download", "downloading");
                }
        }

        public void resetPicture(View view) {
                if (downloadBitmap != null) {
                        downloadBitmap = null;
                }
                imageView.setImageResource(R.drawable.icon);
        }

        public void downloadPicture(View view) {
                dialog = ProgressDialog.show(this, "Download", "downloading");
                downloadThread = new MyThread();
                downloadThread.start();
        }

        // save the thread
        @Override
        public Object onRetainNonConfigurationInstance() {
                return downloadThread;
        }

        // dismiss dialog if activity is destroyed
        @Override
        protected void onDestroy() {
                if (dialog != null && dialog.isShowing()) {
                        dialog.dismiss();
                        dialog = null;
                }
                super.onDestroy();
        }

        // Utiliy method to download image from the internet
        static private Bitmap downloadBitmap(String url) throws IOException {
                HttpUriRequest request = new HttpGet(url);
                HttpClient httpClient = new DefaultHttpClient();
                HttpResponse response = httpClient.execute(request);

                StatusLine statusLine = response.getStatusLine();
                int statusCode = statusLine.getStatusCode();
                if (statusCode == 200) {
                        HttpEntity entity = response.getEntity();
                        byte[] bytes = EntityUtils.toByteArray(entity);

                        Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0,
                                        bytes.length);
                        return bitmap;
                } else {
                        throw new IOException("Download failed, HTTP response code "
                                        + statusCode + " - " + statusLine.getReasonPhrase());
                }
        }

        static public class MyThread extends Thread {
                @Override
                public void run() {
                        try {
                                // Simulate a slow network
                                try {
                                        new Thread().sleep(5000);
                                } catch (InterruptedException e) {
                                        e.printStackTrace();
                                }
                                downloadBitmap = downloadBitmap("http://www.devoxx.com/download/attachments/4751369/DV11");
                                // Updates the user interface
                                handler.sendEmptyMessage(0);
                        } catch (IOException e) {
                                e.printStackTrace();
                        } finally {

                        }
                }
        }

}

Run your application and press the button to start a download. You can test the correct lifecycle behavior by changing the orientation in the emulator via the Ctrl+F11 shortcut.

It is important to note that the Thread is a static inner class. It is important to use a static inner class for your background process because otherwise the inner class will contain a reference to the class in which is was created. As the thread is passed to the new instance of your activity this would create a memory leak as the old activity would still be referred to by the Thread.


Source: http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html

基于遗传算法的新的异构分布式系统任务调度算法研究(Matlab代码实现)内容概要:本文档围绕基于遗传算法的异构分布式系统任务调度算法展开研究,重点介绍了一种结合遗传算法的新颖优化方法,并通过Matlab代码实现验证其在复杂调度问题中的有效性。文中还涵盖了多种智能优化算法在生产调度、经济调度、车间调度、无人机路径规划、微电网优化等领域的应用案例,展示了从理论建模到仿真实现的完整流程。此外,文档系统梳理了智能优化、机器学习、路径规划、电力系统管理等多个科研方向的技术体系与实际应用场景,强调“借力”工具与创新思维在科研中的重要性。; 适合人群:具备一定Matlab编程基础,从事智能优化、自动化、电力系统、控制工程等相关领域研究的研究生及科研人员,尤其适合正在开展调度优化、路径规划或算法改进类课题的研究者; 使用场景及目标:①学习遗传算法及其他智能优化算法(如粒子群、蜣螂优化、NSGA等)在任务调度中的设计与实现;②掌握Matlab/Simulink在科研仿真中的综合应用;③获取多领域(如微电网、无人机、车间调度)的算法复现与创新思路; 阅读建议:建议按目录顺序系统浏览,重点关注算法原理与代码实现的对应关系,结合提供的网盘资源下载完整代码进行调试与复现,同时注重从已有案例中提炼可迁移的科研方法与创新路径。
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文提出了一种基于非支配排序的蜣螂优化算法(NSDBO),用于求解微电网多目标优化调度问题。该方法结合非支配排序机制,提升了传统蜣螂优化算法在处理多目标问题时的收敛性和分布性,有效解决了微电网调度中经济成本、碳排放、能源利用率等多个相互冲突目标的优化难题。研究构建了包含风、光、储能等多种分布式能源的微电网模型,并通过Matlab代码实现算法仿真,验证了NSDBO在寻找帕累托最优解集方面的优越性能,相较于其他多目标优化算法表现出更强的搜索能力和稳定性。; 适合人群:具备一定电力系统或优化算法基础,从事新能源、微电网、智能优化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网能量管理系统的多目标优化调度设计;②作为新型智能优化算法的研究与改进基础,用于解决复杂的多目标工程优化问题;③帮助理解非支配排序机制在进化算法中的集成方法及其在实际系统中的仿真实现。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注非支配排序、拥挤度计算和蜣螂行为模拟的结合方式,并可通过替换目标函数或系统参数进行扩展实验,以掌握算法的适应性与调参技巧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值