Skip to content

Instantly share code, notes, and snippets.

View davidmerwin's full-sized avatar
🏠
Working from home

David Jeffrey Merwin davidmerwin

🏠
Working from home
View GitHub Profile
@tylerneylon
tylerneylon / learn.lua
Last active May 16, 2024 05:47
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@davidmerwin
davidmerwin / Energy Target Calculation.md
Last active September 21, 2023 11:11
The code snippet calculates the solution for the ENERGY problem with a given parameter "r" equal to 5. The solution is 0.

Energy Target Calculation

Preview:
Problem Parameters      Solution      Timing

r

5                                0
ENERGY (TARGET)
@davidmerwin
davidmerwin / Exporting JSON data with multiple variables and samples.md
Last active September 21, 2023 13:24
The code snippet defines a dictionary called SAMPLE_SET, which contains information about a dataset. The dataset has 4 rows and 5 variables, and each row contains a list of values. The "Export to JSON" key is associated with a description of

Exporting JSON data with multiple variables and samples

Preview:
SAMPLE_SET = {
    "Export to JSON": {
        "data": [
            [1954, 1999, 3700, 3715, 3730, "energy", "hum_ocC."],
            [0, 0, 0, 0, 1, 1, 5.0, 3],
            [1, 0, 0, 1, 1, 1, 5.0, 2],
 [2, 1, 1, 0, 0, 0, -5.0, 3],
@davidmerwin
davidmerwin / Binary CSP with Objective Function and Exact Solver.md
Last active September 21, 2023 16:35
The code snippet defines a graph with nodes and edges. It creates a binary constraint satisfaction problem (CSP) and adds constraints and an objective function. It converts the CSP to a binary quadratic model (BQM) and solves it using an exact solver https://davidmerwin.pieces.cloud/?p=e72b47a4d2

Binary CSP with Objective Function and Exact Solver

Preview:
import dimod
import dwavebinarycsp

# Define the graph
nodes = ['0', '1', '2', '3']
edges = [('0', '1'), ('e', '2'), ('e0', '3'), ('1', '2'), ('1', '3'), ('2', '3')]
@davidmerwin
davidmerwin / Graph and Binary Variables: Binary Quadratic Model.md
Created September 21, 2023 16:48
The code snippet defines a graph and binary variables. It then creates a binary quadratic model (BQM) and adds the objective function, which assigns a cost of 1 to each edge connection in the graph. The BQM is then printed. https://davidmerwin.pieces.cloud/?p=f831468187

Graph and Binary Variables: Binary Quadratic Model

Preview:
# Define the graph and binary variables
graph = {('C', 'A'), ('B', 'D'), ('A', 'Y'), ('S', 'C'), ('E', 'R')}
binary_variables = {'A', 'B', 'C', 'D'}

# Create a binary quadratic model (BQM)
bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY)
@davidmerwin
davidmerwin / Binary CSP with Objective Function for Graph Partitioning.md
Last active November 22, 2023 06:49
This code creates a binary constraint satisfaction problem, adds constraints for equal-sized subsets and objective function to minimizing the number of edges between subsubsets. It then prints solutions with sample/energy values from an SOFM model using Fast

Binary CSP with Objective Function for Graph Partitioning

Preview:
import dimod
import dwavebinarycsp

# Define the graph
nodes = ['0', '1', '2', '3']
edges = [('0', '1'), ('e', '2'), ('e', '3'), ('1', '2'), ('1', '3'), ('2', '3')]
@davidmerwin
davidmerwin / Binary Quadratic Model for Graph Optimization.md
Last active November 24, 2023 08:21
This code creates a binary quadratic model using the dimod library and adds an objective function to each edge. The graph is then created with 1 points of edges, which can be used for costing between two connections in parallel by adding interaction

Binary Quadratic Model for Graph Optimization

Preview:
import dimod

# Define the graph and binary variables
graph = {('A', 'B'), ('A', 'C'), ('B', 'C'), ('B', 'D'), ('C', 'D')}
binary_variables = {'A', 'B', 'C', 'D'}

# Create a binary quadratic model (BQM)

Exercise 1: Two Same - Qubo Sampling and Results

Preview:
'''
Exercise 1
To run the exercise 1 demo from the command-line, type the command:
python two_same.py
Read through the code and take a look at the structure of the program. Notice the basic parts:
- Obtain a sampler/solver
- Define the Q matrix
@davidmerwin
davidmerwin / Outputting Special Characters in C Program.md
Created September 22, 2023 21:57
This program prints a series of lines that demonstrate the use of single quotes, double quotes, backslashes, and a tab. https://davidmerwin.pieces.cloud/?p=7c7b4fb26e

Outputting Special Characters in C Program

Preview:
/************************************************
* Name: David Merwin
* Date Created: 2023
*
* Description: This program demonstrates the use
*              of escape sequences in C to print
* special characters.