Posts

Showing posts from May, 2018

Applying a genetic algorithm to the quadratic assignment problem in C#

Image
Some sample C# code on how a genetic algorithm can be applied to the quadratic assignment problem. The quadratic assignment problem (QAP) is a combinatorial optimization problem that models the following real-life problem: Given a set of n facilities and a set of n locations, specify a distance for each pair of locations and a flow for each pair of facilities, the objective is to assign each facility to a different location such that the sum of the distances multiplied by the corresponding flows is minimised. The problem statement resembles that of the assignment problem, except that the cost function is expressed in terms of quadratic inequalities, hence the name. This example is implemented as a simple console application using C# code developed in Microsoft Visual Studio. To help break down the problem a little, I develop a number of classes for the purposes of encoding potential solutions as chromosomes, maintaining a population of chromosome and applying genetic oper...

Enabling vertical scrolling of html in the Chromium web browser control

Image
A short post comtaining some example XAML code on how to enable vertical scrolling in a WFP application containing a Scrollviewer command that uses the CEFsharp browser control. Step 1: Create a new WPF project Step 2: Install CEFsharp See this post on how to use NuGet to install CEFsharp: Using the CefSharp Chromium Web Browser in WPF / XAML Step 3: Update the XAML code MainWindowViewModel.cs A border and margin is used so that we can better illustrate how the web browser content may be scrolled when the size (height) of the content being viewed exceeds the size of the WPF window. The url of the Chromium browser is set to be the Amazon website address. The height of the Chromium web browser control is set to 800 so that it exceed the height of the control, thereby forcing the vertical scrollbar to become visible. [code language="csharp"] <Window x:Class="CefSharpScroll.MainWindow" xmlns="http://schemas.microsoft.com/winfx/...